Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top