Gitorious: Per-repository post-receive hooks

Gitorious version 2.3 brought official support for server-wide custom post-receive hooks, which means you do not to use hacks anymore. The custom hooks are used for all repositories, and do not offer per-repository hooks. This article shows you how to do it.

At first, create the custom-post-receive hook file in $gitorious-install-dir/data/hooks/ and make it executable:

# run all post-receive.* hooks in custom-hooks/
if [ ! -d custom-hooks ]; then
cat - > "$FILE"
for i in custom-hooks/post-receive.*; do
    [ -x "$i" ] && cat "$FILE" | "$i"
rm "$FILE"

Now, in each of the repositories that need a post-receive hook, create a directory custom-hooks and copy or symlink a post-receive hook into it:

$ cd /var/data/git/repositories/project/demo.git/
$ mkdir custom-hooks
$ echo '#!/bin/sh
echo Current date: `date`' > custom-hooks/
$ chmod +x custom-hooks/

When pushing to this repository, you will get the following output:

Writing objects: 100% (3/3), 336 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: => Syncing Gitorious... Current date: Sat Dec 31 17:42:23 CEST 2012

Written by Christian Weiske.

Comments? Please send an e-mail.