The ability to update and close Trac tickets associated with a given repo whenever a commit is made to that repo is pretty handy. No more committing, going to the Trac site, updating. I found several guides on setting this up floating around, this one being the most informative. However, I’d like to clearly state the steps here, as I found most of the guides rather muddled, when the process is really quite simple.
In these examples, I will assume:
- Your SVN repo (master): /var/svn/repositories/code
- Your Trac instance: /var/trac/code
Add and edit a post-commit script
In /var/svn/repositories/code/hooks, there should be a post-commit.tmpl added by the initialization of the repo. Copy this and edit the copy:
1 2 | sudo cp post-commit.tmpl post-commit sudo vim post-commit |
The file consists of lots of informative comments, and some uncommented stuff a the bottom. Delete all the uncommented stuff and add:
1 2 3 4 5 | REPOS="$1" REV="$2" TRAC_ENV="/var/trac/code" /usr/bin/python /var/svn/repositories/code/hooks/trac-post-commit-hook.py \ -p "$TRAC_ENV" -r "$REV" |
Add a trac-post-commit-hook.py file
In /var/svn/repositories/code/hooks, export the trac-post-commit-script:
1 2 | sudo svn export http://svn.edgewall.com/repos/trac/trunk/contrib/trac-post-commit-hook \ trac-post-commit-hook.py |
You shouldn’t need to edit this.
Depending on your permissions setup for your SVN repo, you will need to change the ownership of the trac-post-commit script, as well as the post-commit script made above. In my case, I have svn:svn on all associated files, so at this point I ran:
1 | sudo chown svn:svn /var/svn/repositories/code/hooks/* |
Change perms on your Trac db dir
When you perform the commit, svn will execute what is in post-commit, which hits the trac-post-commit script, which then tries to update your Trac instance. For that to be possible, it needs access to your Trac db. How to do that totally depends on what access method you have for svn. In my case, I use svn+ssh, so it is my user (and others that commit, so configuring for an ‘svn’ group is easier) that needs access. If you aren’t sure, or to test, this should work:
1 | sudo chmod -R a+w /var/trac/code/db |
Test
Now when you perform a commit to something in the code repo in our example and the change is associated with, say, ticket 456, your comment could be:
* Fixed problem X, logged state Y. closes ticket:456
And immediately thereafter, ticket 456 would have a comment such as:
1 | (In [REVNUMBER]) * Fixed problem X, logged state Y. closes ticket:456 |
and be closed.
The Trac FAQ entry on hooks to commits has additional troubleshooting steps for configuration. As long as you don’t have a crazy svn and/or Trac setup, however, this should be relatively easy to get going.









Hi There!
Thank you very much for your post. I’m using trac 0.11.4 with agilo plugin. I don’t know why but it didn’t work for me. Actually my trac was getting the commit updates until I installed agilo plugin.
My svn and trac folders are both within my personal folder, so I believe that it’s not a problem with permission. If you could please help me… Thank you very much.
@Felipe: I haven’t used the agilo plugin, but it sounds like it was the cause of the breakage. Perhaps the agilo team can be of assistance. Good luck!
I was getting post-commit errors with no output until I made post-commit script executable:
chmod +x /var/svn/repositories/code/hooks/post-commit
http://trac.edgewall.org/browser/trunk/contrib/trac-post-commit-hook?rev=8427
If like me you can’t find trac-post-commit-hook
Hi, I have been trying to get trac-post-commit-hook to work for a while now. It just doesn’t work for me no matter what I do. I have the trac-post-commit-hook and i have followed numerous tutorials. I also did what is listed above and it still didn’t work. My SVN server uses the latest Ubuntu server + Apache2 + SVN + trac 11.7. I use TortoiseSVN program on Windows7 to commit to the svn server. Every time i make a commit, i get an error that says “post-commit hook failed (exit code 255) with no output.” Any ideas what is going on?
Please and Thanks
- Rith
@Fernando: that’s an old revision of the script. You should get the script that matches the Trac release you’re running, which can be found in the branches directory (http://svn.edgewall.com/repos/trac/branches) of the Trac project.
See also http://trac.edgewall.org/wiki/TracFaq#can-trac-automatically-update-a-ticket-when-i-commit-a-changeset
This valuable blog post, “Updating Trac tickets in svn commits | tail -f
findings.out” shows the fact that u comprehend what precisely you r
speaking about! I really totally approve. Thanks a lot -Cedric
This unique posting, “Updating Trac tickets in svn commits | tail -f findings.
out” reveals the fact that u truly understand just what you’re talking about! I personally 100 % approve. Thanks -Darrell
Where did you actually pick up the ideas to publish ““Updating Trac tickets in svn
commits | tail -f findings.out”? Thank you -Jamaal