2
(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?

cnd
  • 32,616
  • 62
  • 183
  • 313

2 Answers2

5

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...)

Eli Barzilay
  • 29,301
  • 3
  • 67
  • 110
0

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.

Community
  • 1
  • 1
Nicolas Dudebout
  • 9,172
  • 2
  • 34
  • 43
  • I think I must to use something without async here, magit was not designed for it as @Eli Barzilay said. There is no conceptual end-goal I just need to sync some git repositories and maybe add some addition scripting yet it's simple until I discover how can I improve it using elisp, for example buy adding configuration file. – cnd Jun 22 '12 at 03:51