git: empty arguments in post-receive hook
There are no arguments though the information is passed over STDIN. To read that information from bash simply do this:
read oldrev newrev refname
echo "Old revision: $oldrev"
echo "New revision: $newrev"
echo "Reference name: $refname"
I'm just summarizing the answers already posted.
The post-receive
hook doesn't take any arguments. Quoth the manual (emphasis added):
This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. It executes on the remote repository once after all the refs have been updated.
This hook executes once for the receive operation. It takes no arguments, but gets the same information as the
pre-receive
hook does on its standard input.This hook does not affect the outcome of
git-receive-pack
, as it is called after the real work is done.This supersedes the
post-update
hook in that it gets both old and new values of all the refs in addition to their names.Both standard output and standard error output are forwarded to
git send-pack
on the other end, so you can simply echo messages for the user.The default
post-receive
hook is empty, but there is a sample scriptpost-receive-email
provided in thecontrib/hooks
directory in git distribution, which implements sending commit emails.
I stumbled into this problem while setting up a continuous integration server. Since the arguments are not passed to post-receive via the command line, but are passed over STDIN, you have to use the read command to fetch them. Here is how I did it:
#!/bin/sh
read oldrev newrev refname
BRANCH=${refname#refs/heads/}
curl --request POST "http://my.ci.server/hooks/build/myproject_$BRANCH"