tags:

views:

34

answers:

1

I'm writing post-receive hook basing on the post-receive-email script from the contrib dir, but it seems that the oldrev and newrev arguments are empty.

The script looks like this:

#!/bin/bash

oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)

The script runs on push, but all $1, $2, $oldrev and $newrev are empty. Should I configure something to get it running?

(The repository was created by gitolite if it does matter)

+1  A: 

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 script post-receive-email provided in the contrib/hooks directory in git distribution, which implements sending commit emails.

Jörg W Mittag