8

The git-hooks pre-push documentation states that the first line of stdin will be populated with the local ref and sha, and the remote ref and sha as such:

<local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF

However, my simple pre-push script:

#!/bin/bash

echo "params=[$@]"

read line
echo "stdin=[$line]"

exit 1

returns the following output when a $git push is run:

params=[origin [url]:[branch].git]
stdin=[]
error: failed to push some refs to '[remote]'

The parameters to the script are as specified in the documentation (name and path of the remote). The error is expected because my script exits with a status of 1. However, I can't seem to figure out why I'm not receiving the local and remote refs on stdin as specified by the documentation.

Is this a bug in git? Or, am I missing something?

1 Answer 1

12

Apologies if this is stating the obvious, but if there's nothing to push, you won't get any lines on stdin. The sample .git/hooks/pre-push.sample has a while loop:

IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
    ...
done

and that appears to work when I try it here with an echo inside that loop and nothing else - I get nothing when I have nothing to push, and output when I do.

Sign up to request clarification or add additional context in comments.

8 Comments

I haven't checked yet but I'm sure this is exactly what's happening. The problem is I was misunderstanding the convention you outlined above. Thank you for clearing that up!
@dcow This would suggest that a small documentation patch to clarify the issue would be in order ;-) github.com/git/git/blob/master/Documentation/SubmittingPatches
@PhilipOakley posted to the mailing list. Would you be so kind as to take a look?
@dcow I thought it looked good, apart from one spelling "beilieve", and that somehow three copies were generated (any ideas?). I see Junio (maintainer) has done his usual thing of trying to ensure the clarification covers the other areas that maybe hadn't been considered.
Apparently there is another possibility: if the push is non-fast-forward but no --force was supplied then the script is called but without any input on stdin. If --force is added to the otherwise unchanged command line stdin is getting input as it should. This is still undocumented (unlike the arguments, thanks guys ;)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.