如何同步运行magit

cnd*_*cnd 2 emacs elisp magit

(let ((default-directory "/home/vision/"))
  (magit-pull)
  (magit-fetch "upstream")
  (magit-merge "upstream/master")
  (magit-push))
Run Code Online (Sandbox Code Playgroud)

我越来越:

Running git fetch upstream
Git is already running
Run Code Online (Sandbox Code Playgroud)

我怎么能等待获取结束?

Eli*_*lay 5

Magit旨在作为git的交互式前端,所以类似magit-fetch的东西并不是真的要从你的代码中运行......但是如果你真的坚持,快速查看代码会告诉你这magit-process是一个保存过程的变量当它正在运行时,它完成后就会被清除.因此,您可以使用一个等待直到发生的循环:

(progn
  (magit-fetch "upstream")
  (while magit-process (sleep-for 0.25))
  (magit-fetch "upstream"))
Run Code Online (Sandbox Code Playgroud)

但这确实是推动它 - 例如,当提取失败时会发生什么?

顺便说一下,你能做的另一件事就是看一下这个magit-fetch案例中的单行函数:

(apply 'magit-run-git-async "fetch" remote magit-custom-options)
Run Code Online (Sandbox Code Playgroud)

并编写使用非异步版本的代码:

(progn
  (apply 'magit-run-git "fetch" "upstream" magit-custom-options)
  (apply 'magit-run-git "fetch" "upstream" magit-custom-options))
Run Code Online (Sandbox Code Playgroud)

(你可以建议一个补丁来添加一个可选的标志参数,但这似乎是一个交互式工具的一个iffy功能...)