Updating the Status of a Trac ticket via a SVN commit

February 3, 2008 · 9 Comment s

One of the really nice things about the SVN/Trac combo is that when you commit changes to SVN, you can have the changeset update the status of a Trac ticket.

So, say the changes you have been working on, have tested, and are now committing back to SVN fix a specific ticket within Trac, and once you've made your commit, you would then log into Trac and close the ticket there.

You could also do this via the superb Mylyn integration if you're using Eclipse - which you should be :)

Well, how about updating the actual status when you do your commit? One action to rule them all, so to speak.

Well, this is possible, and here's how to do it.

The main reason for posting this, is that I've recently upgraded our Trac environment from 0.10 to 0.11 and I noticed the trac-post-commit was now broken.

The following is for Linux, so you'll need to Google for Windows.

Grab the trac-post-commit script

You need to pull the latest working version of the script from the Trac SVN repository.

svn export http://svn.edgewall.com/repos/trac/trunk/contrib/trac-post-commit-hook /my/svn/repo/hooks

Next rename the file you've just exported by sticking a ".py" on the end - it's a Python script.

Next make sure your post-commit script file is named appropriately (post-commit funnily enough) and make sure that execute permissions are set on the file. You know, chmod ugo+x post-commit

Edit the post-commit script

Next, edit your post-commit file and add the following line - this is the reason ours was broken.

TRAC_ENV=<span class='cc_value'>"/path/to/your/trac/env"</span>

Now add the following line, and this is the one that calls the trac-post-commit script

/usr/bin/python /path/to/hooks/trac-post-commit-hook.py -p <span class='cc_value'>"$TRAC_ENV"</span> -r "$REV

Just to be on the safe side of everything, just Apache a restart.

Commit Your Change

Now, from within Eclipse, when you want to commit your changes, you can now put the following in your comments (and you are filling in comments aren't you?????!!!???"

command #1
command #1,#2
command #1 & #2
command #1 and #2

The following commands are supported:

  • close
  • closed
  • closes
  • fix
  • fixed
  • fixes

The above will close the specified ticket number, in addition to adding the message you have specified.

Also, you can use the following commands:

  • references
  • refs
  • addresses
  • re
  • see

The ticket numbers specific here are left as is, but the contents of the commit messages are added to their notes.

A quick example would be something like:

The changes made here fix #100, #102 and refs #85

This commit message will close tickets 100 and 102, and add the commit message to ticket 85.

Tags: Trac · Subversion

9 response s so far ↓

  • 1 Big Mad Kev // Feb 4, 2008 at 7:40 AM

    Remember the commands are Case Sensitive, and if Like me you can use ticket:10 rather then #10 Keep those # safe for CF ;)

    This is going to be one of my next video sessions.
  • 2 Warning // Feb 4, 2008 at 9:16 AM

    You've got the day/month swapped in the urls submitted to MXNA
  • 3 Andy Allan // Feb 4, 2008 at 11:39 AM

    Personally I blame BlogCFC for favouring US dates :)
  • 4 mga // Mar 14, 2008 at 10:58 AM

    Hi,
    thank you for this post.
    All is right with the displaying of svn commit messages in trac, but I have a problem with the comments that are written on more than 2 lines.
    For example, in eclipse, if the comment is 'a comment in eclipse', then in trac, you see 'a comment in eclipse', but if the comment is :
    'a line in eclipse
    a second line in eclipe'
    then, in trac, le messages is :
    'a line in eclipse a second line in eclipe'
    all is on one line.
    Do you have the same problem ?
    if not, what to do in trac for displaying the carriage return that is in the svn commit message ?

    thanks for your answer.
  • 5 Bernard // Nov 9, 2008 at 4:43 PM

    Thanks a lot for the info. I do have some remarks (stuff I needed to make it work here), and because this was the first hit in google when I searched for the problem, I decided to share them.

    First note that I chose to put the trac-post-commit script in /var/trac/ and that I named it trac-post-commit.py.
    My SVN repository is located in the following directory: /var/svn/myproject
    My trac environment is located here: /var/trac/myproject

    So here are the remarks:

    1) You need to get the script matching your trac version. If it doesn't match, it may not work.

    You can use the following command to know which trac version you are using:
    trac-admin about | head

    If this shows you're using version 0.10.4 for example (my case), you can use the following command to obtain the script:

    sudo svn export http://svn.edgewall.com/repos/trac/branches/0.10-stable/contrib/trac-post-commit-hook /var/trac/trac-post-commit-hook.py

    Note that there is no need to first get the file, and then rename it (it can be done in one command).

    2) I lost you in your explanation about the post-commit script. I did some research and this is how/where I had to create the script (I didn't have such script yet).

    The following commands create the script (based on an existing template file):

    cd /var/svn/myproject/hooks
    sudo cp post-commit.tmpl post-commit
    sudo chmod ugo+x post-commit

    Now you need to modify the post-commit script (eg by running 'sudo pico /var/svn/myproject/hooks/post-commit').
    You need to comment out the existing lines, and add the following:
    REV="$2"
    TRAC_ENV="/var/trac/immoville"
    /usr/bin/python /var/trac/trac-post-commit-hook.py -p "$TRAC_ENV" -r "$REV"

    3) Now you need to give the trac-post-commit-hook script read/write access your project's trac database and it's directory (which wasn't the case yet here):
    sudo chmod -R a+rw /var/trac/myproject/db

    4) It was not necessary to restart apache. This is quite logical, since the script is called by SVN when you do a commit, and it modifies the trac database. No apache settings are changed in the process.
  • 6 warhammer gold // Nov 20, 2008 at 3:40 PM

    <A href="http://www.vipwarhammergold.com/"; target=_blank><FONT =4><B>warhammer gold</B></FONT></A> <FONT =4></FONT><A href="http://www.vipwarhammergold.com/news/news.html"; target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.bestwarhammer.com/"; target=_blank><FONT size=4><B>warhammer gold</B></FONT></A><FONT size=4></FONT> <A href="http://www.bestwarhammer.com/news/news.html"; target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.aocsale.com/"; target=_blank><FONT size=4><B>aoc gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.aocsale.com/aoc-news/"; target=_blank><FONT size=4><B>age of conan gold</B></FONT></A><BR><A href="http://www.game4power.com/"; target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.game4power.com/news/"; target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.game4power.com/"; target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A><BR><A href="http://www.gamelevelup.com/"; target=_blank><FONT size=4><B>wow power leveling</B></FONT></A><BR><A href="http://itemstores.com/"; target=_blank><FONT size=4><B>wow item</B></FONT></A>
  • 7 wholesale // Aug 8, 2009 at 6:17 AM

    Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.
  • 8 cctv monitors // Aug 28, 2009 at 10:29 AM

    I bookmarked this already dude great work
  • 9 ed hardy mens Jeans // Sep 17, 2009 at 8:46 AM

    Thank you!

Leave a Comment

Leave this field empty: