Asynchronous git hook?

青春壹個敷衍的年華 提交于 2019-12-05 15:49:36

问题


I execute unit tests on post-receive but don't want the user to wait for it.

I tried the suggestions from the git-user mailing list ("just & it") but this is not working: https://groups.google.com/forum/#!topic/git-users/CFshrDgYYzE

git seems to wait for the bash script to exit even if I just put this in hooks/post-receive:

exec-unit-tests.sh &

回答1:


This worked for me. & and the stdout & stderr pipe must be closed:

long-running-command >&- 2>&- & 

In order to put the command in the background, both stdout AND stderr must be closed. If either of them is left open the process won't be in the background, and the commit operation won't complete until the hook script is finished.

A lazy alternative approach is to simply redirect stdout and stderr to /dev/null:

long-running-command >/dev/null 2>&1 & 

This is a bit less clean, but perhaps easier to understand and remember, and it has the same effect.



来源:https://stackoverflow.com/questions/17727315/asynchronous-git-hook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!