Trac and SVN on Mac OS X

I quite like Trac as its an integrated Wiki, ticketing system, and SVN repository browser. I particularly like the fact that you can create links between any of these three: Wiki pages can contain links to SVN commits, tickets can contain links to wiki pages and commits, you can even set it up so SVN commit messages automatically close tickets (and insert a link to the commit that closed the ticket). Its simple but nice.

This post is how I have set it up on my iMac. I was after a simple installation approach where I am the only user.  This is for Trac 0.12.1.

Creating a Subversion Repository

I installed Xcode first, so I am not sure if Subversion was installed with Xcode, or if it just came with the OS. But it was already installed so no software install was required. I created /Library/Subversion/Repository/HelloIphone3 (where “HelloIphone3” is my project name). I tend to create a subversion repository per project (this may be overkill). The following commands are from a “Terminal” window (under Applications, Utilities).

$ mkdir -p /Library/Subversion/Repository
$ svnadmin create /Library/Subversion/Repository/HelloIphone3

Using Xcode I then imported the project from Xcode into SVN, and checked it out again into Xcode (as described in the Xcode documentation). Then Xcode knew the project was all being managed by SVN.

Installing Trac Software

First I installed the Trac software.  (I did not keep notes when I started, so the following may have errors.) I followed the Trac installation page.

$ easy_install Babel==0.9.5 Genshi==0.6
$ easy_install Trac
$ easy_install -U Trac

Creating a Trac Environment

I created a Trac “environment” for the project.  I decided to create Trac environments under /Library/Trac/Environment to follow a similar pattern as for Subversion repositories. Each Trac environment I am going to create with the same name as the repository name.

$ mkdir -p /Library/Trac/Environment
$ trac-admin /Library/Trac/Environment/HelloIphone3 initenv

It prompted for a project name (I entered “HelloIphone3” again) and a database connection string (I just hit return to accept the default, which was to use the built in SQLite database).

Environment Authentication

I created an account for myself.  I decided to use “basic” authentication as its all local – no security concerns.  (I did not really want authentication, but I could not see how to get administrative access without an account.  I did not look very hard mind you!)

$ htpasswd -c /Library/Trac/Environment/htpasswd myusername

It prompts for the password to use for the new user (I did not really use “myusername” of course).  I kept the password file outside the environment so I can share it between all environments easily. (I pass it on the command line of the tracd process below.) I then told Trac I was an administrator.

$ trac-admin /Library/Trac/Environment/HelloIphone3 permission add myusername TRAC_ADMIN

Starting Trac

I decided to use the Trac built in HTTP daemon (tracd) so I did not have to configure Apache or similar.  To run I settled on the command line

$ tracd -p 8000 --hostname=localhost --basic-auth="*,/Library/Trac/Environment/htpasswd,Localhost" \
    -e /Library/Trac/Environment

Here -p 8000 is the port, --hostname=localhost means it won’t accept remote connections, --basic-auth defines the password file location (* means all environments, and “Localhost” is the relm name), -e says list all environments under the specified directory, so I don’t need to change the tracd configuration every time I create a new environment.

TODO: I want to start using launchctl, but I cannot get it to work or see any error messages. Help or suggestions appreciated! I want to run as my normal user, on demand would be nice. For now I restart by hand (with a shell script). I am hoping I don’t get file permission issues here since I did everything as my normal login, not root.

Keeping SVN and Trac in Sync

I then told Trac about the SVN repository. I went to the Trac home page (http://localhost:8000/), selected the HelloIphone3 environment from the list, authenticated, then clicked on the “Admin” button (on top right of page). I clicked on “Repositories” (bottom left) to register the SVN repository. On the right is an “Add Repository” panel. I typed “HelloIphone3” as the repository name, selected “svn” as the repository type, and entered “/Library/Subversion/Repository/HelloIphone3” as the directory. Then I clicked “add”.

After adding the repository, you need to tell Trac to sync the SVN repository with Trac. This is done using

$ trac-admin /Library/Trac/Environment/HelloIphone3 repository resync

To tell Trac about each commit, you need a svn commit hook.  If you don’t have a commit hook yet, start with the supplied template file

$ cd /Library/Subversion/Repository/HelloIphone3/hooks
$ cp commit-hook.tmpl commit-hook
$ chmod +x commit-hook

Then edit the file and add the following two lines near the end

trac-admin $ENV changeset added HelloIphone3 $REV

I commented out the line starting with on the assumption its sending out email per commit, which I don’t need as I am the only committer.

Auto linking Commit Messages with Trac Tickets

Next, so that you can refer to tickets (including closing them) from Xcode in the SVN commit message (e.g. by including “See #41” or “Fixes #23” in the commit message), go to the Trac “Admin” page again, select “Plugins” from the right sidebar menu, expand the “Trac 0.12.1” tree in the middle section, scroll down to near the end where it says “CommitTicketReferenceMacro” and “CommitTicketUpdater”, tick the checkbox next to both (expand the items to see more instructions on how to use it), then click “Apply Changes” at the bottom of the page.

Easy huh? I have tested for all of 2 minutes now, so it must be right!


  1. Just wanted to add another option worth considering. is a Mercurial hosting site with private repositories, wikis, and issue tracking (very much like Trac). Being hosted its good for offsite backups. It can even be accessed via SVN (so should be possible to get Xcode to talk directly). Up to 5 users is free (when I just looked), so a serious alternative to consider for small projects. Does not seem to have any storage limits.

    (There is also Github if you prefer git to Mercurial – but I slightly prefer the look and sound of Mercurial over Git from what I have read.)

  2. Patrik · · Reply

    Great post, I struggled quite a bit at getting the commit hooks working, this made me find the way.

    Regarding the launchctl bit, I created a launch daemon using the Lingon editor, Just enter the launch command for tracd as the command to run, but make sure to include the path to tracd. Note that this will make it run on system boot, not on demand.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: