Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catching a git post-receive error in a script

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?

like image 631
Jistanidiot Avatar asked Oct 18 '12 18:10

Jistanidiot


1 Answers

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.

like image 180
Jistanidiot Avatar answered Oct 21 '22 05:10

Jistanidiot