[clug] Using Trac with Git
direvus at gmail.com
Mon Aug 31 23:49:53 MDT 2009
Back at the January CLUG meeting, Paul gave a talk demonstrating how
easy it is to set up post-commit hooks between Subversion and Trac
(thanks Paul!) so that when you write a commit message that says
something like "this fixes ticket #174", it automatically drops your
commit message into the ticket and marks it as resolved.
Well I've recently migrated one of my projects from Subversion to Git,
and I decided to see about getting this working with the new Git+Trac
It turned out to be refreshingly simple.
Much like with Subversion, the Trac trac-post-commit-hook script does
all the heavy lifting for you; it taps directly into the Trac
environment using Trac's own Python API and looks up the commit
message, parses it for references to tickets and appends changes to
All you have to do is make sure that the Git repository calls this
Git has a hooks system which is quite flexible. I ended up
plaigarising an existing example script for sending commit emails to a
mailing list with the "post-receive" hook .
So really all I needed to do was drop the following into
hooks/post-receive in my master repository, make it executable:
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
/usr/bin/python $trac_hook -p $env_path -r $2
while read oldrev newrev refname
/usr/bin/python $trac_hook -p $env_path -r $newrev
After that, the whole thing Just Worked.
The only thing you need to be wary of is that the Debian trac package
doesn't include the trac-post-commit-hook script. It's completely
daft, and they've had a bug report in there since this time last year
. So if you're using Debian/Ubuntu you'll need to install this
script yourself. Other than it really is a breeze.
More information about the linux