문제

In a bash script I do a

git push

and I check its exit status.

On the remote server there's a post-receive hook which does a few things. If an error occurs the post-receive hook will exit with a non-zero value.

However when the post-receive hook errors out, git push exits normally. Unless I'm specifically checking the output for specific error strings (which I'm not) my script thinks everything went ok.

Is there an easy way for me to determine if the post-receive hook failed?

도움이 되었습니까?

해결책

So the answer is no there is no way to easily check if the post-receive hook failed. The best you can do is have your script check for output from remote and make sure your post-receive hook echos an error message you're looking for.

In my case a pre-receive hook won't work since I'm pushing to another backup repo and the new commit has to be accepted before it can be pushed.

Basically the post-receive hook should do something like:

 some-command-that-might-fail

 RC=$?

 if [ $RC -eq 0 ]; then
echo -e "\nERROR: some-command-that-might-fail FAILED!!!!!!!! PANIC!!!!!!\n"
 fi

Then the script doing the push should grep the output for FAILED or ERROR or PANIC and report the post-receive error.

다른 팁

Quoting from http://www.kernel.org/pub/software/scm/git/docs/githooks.html#post-receive:

post-receive
...
This hook does not affect the outcome of git-receive-pack, as it is called after the real work is done.

Maybe the pre-receive hook is better suited for your purpose, although there's no mention of a return code transmitted.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top