Git-hooks pre-push script does not receive input via STDIN

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

  • Why don't git colors show up in iTerm2
  • Git: unable to redirect/parse the output of 'git fetch --dry-run' command
  • Git pre-commit hook to find text in files
  • “git add” using wildcard is not functioning as I hoped - must I cd into specific directories?
  • Unable to install the latest version of Gitlab
  • Bash PS1 settings - how to get the current folder back as the terminal title
  • 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?

  • How to setup github repository in my NetBeans IDE?
  • Adding git alias to .bash_profile not working
  • How to use git branch with Android Studio
  • Is there a way to use review board with git without manually uploading diffs through the web interface every time?
  • How to get TeamCity Build trigger filter to build feature branches but not default branch
  • Is there a way to lock a branch in GIT
  • One Solution collect form web for “Git-hooks pre-push script does not receive input via STDIN”

    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.

    Git Baby is a git and github fan, let's start git clone.