Search code examples
gitgit-post-receive

what is the content of post-receive.sample?


I'm missing the hooks/post-receive.sample file that is allegedly just a short script. Would you please care to write me its content?

That was my question above, but stackoverflow did not accept it, maybe it was too short, so I add some more content.


Solution

  • All hooks in git are by default empty scripts, with a few comments describing what happens. You can simply create a script like below to find out what parameters the script is called with, and reverse-engineer the meaning of them:

    #/bin/bash
    echo $@
    

    In case of the post-receive hook, it is the following, which comes from the link @jurgemaister provided.

    # The "post-receive" script is run after receive-pack has accepted a pack
    # and the repository has been updated.  It is passed arguments in through
    # stdin in the form
    #  <oldrev> <newrev> <refname>
    # For example:
    #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
    

    Your hook will obviously do something specific for you, so you have to write your own script there with the corresponding variables $1 (oldrev), $2 (newrev), and $3 (refname).