异步的git钩子? [英] Asynchronous git hook?

查看:93
本文介绍了异步的git钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在post-receive上执行单元测试,但不希望用户等待它。

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

我尝试了git-user邮件列表中的建议( 只是& 它),但这不起作用: https://groups.google.com/forum/#!topic/git-users/CFshrDgYYzE

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似乎等待bash脚本退出,即使我只是把它放在hooks / post-receive中:

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

exec-unit-tests.sh &


推荐答案

这对我有用。 & 以及stdout&必须关闭stderr管道:

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

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

为了将命令放在后台, stdout AND stderr 必须关闭。如果其中任何一个都处于打开状态,则该进程将不在后台,并且在完成该钩子脚本之前,提交操作才会完成。

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.

一个懒惰的替代方案方法是简单地将 stdout stderr 重定向到 / dev / null

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.

这篇关于异步的git钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆