(let ((default-directory "/home/vision/"))
  (magit-pull)
  (magit-fetch "upstream")
  (magit-merge "upstream/master")
  (magit-push))

I'm getting:

Running git fetch upstream
Git is already running

How can I wait for fetch finish?

有帮助吗?

解决方案

Magit is intended as an interactive front-end for git, so things like magit-fetch are not really intended to be run from your code... But if you really insist, a quick look at the code shows you that magit-process is a variable that holds the process while it is running, and it's cleared when it's done. You can therefore use it with a loop that waits until that happens:

(progn
  (magit-fetch "upstream")
  (while magit-process (sleep-for 0.25))
  (magit-fetch "upstream"))

But that's really pushing it -- for example, what happens when the fetch fails?

BTW, another thing that you can do is look at the source which is a one-line function in the magit-fetch case:

(apply 'magit-run-git-async "fetch" remote magit-custom-options)

and write code that uses the non-async version:

(progn
  (apply 'magit-run-git "fetch" "upstream" magit-custom-options)
  (apply 'magit-run-git "fetch" "upstream" magit-custom-options))

(And you can suggest a patch to add an optional flag argument, but that seems like an iffy feature for an interactive tool...)

其他提示

This question seems to be related to your previous question. You are trying to solve your problem of using git from within emacs with two approaches:

  • converting a bash script line by line in to emacs lisp
  • using an existing library to interact with git

Your first approach was clearly not working and your second approach seems better. However, magit is not meant to be used from your code. The functions could change at any time since magit is only interested in the front-end. Any change that does not break the functionality will be deemed safe.

It would be useful if you explained what your end goal is so that you can get a better answer. What you need might be a simple git alias that you can call from emacs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top