For the University games project unit this year, my group are using Git for version control and trac for project management and bug tracking. It was decided that all members of the group should be emailed upon any commits to the repository. This was easy enough to implement, only requiring the renaming of a sample post-receive script and configuration of a few variables.

The tricky part was when I needed to set up a second post-receive script which allowed people to put tags in their commit messages to update trac tickets. The problem was that it would seem that there is not any built-in support for multiple post-receive scripts so you need to implement it yourself.

Initially I just created a single shell script which called both post-receive scripts. Unfortuantely this didn’t seem to work. So why!? It turned out that the input to the scripts is piped in on stdin and that the email script was just eating up the whole lot leaving nothing for the trac script to use! To get around this, I found a Stack Overflow question with code which copies the input from stdin to a temporary file and then pipes that into both post-receive scripts.

#!/bin/sh

FILE=mktemp
cat - > $FILE

cat $FILE | /srv/gitosis/repos/bloodbrothers.git/hooks/post-receive-email
cat $FILE | /srv/gitosis/repos/bloodbrothers.git/hooks/post-receive-trac

rm $FILE

Following this, bizarrely, tickets were still not being updated. Eventually I found the problem was that I had the incorrect permissions set on my trac directory. This meant that when my trac post-receive script tried to call trac-admin, it didn’t actually have permission to write to the trac database. After giving the gitosis user access, my tickets began magically updating :D

Tagged with:
 

2 Responses to Multiple post-receive hooks for Git

  1. Felix says:

    I like this syntax better:

    while read oldrev newrev refname
    do
    echo $oldrev $newrev $refname | /bin/sh /path/to/post-receive-email
    echo $oldrev $newrev $refname | /usr/bin/python /path/to/git_buildbot.py
    done

    from

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>