Installing Trac (with git) in Fedora 15/16 [Part 2]

My previous post got trac setup and running with SVN as the version control system. This post will show you how to get trac working with git as the version control system. When you installed trac using the command in the last post you will have also installed the trac git plugin. If you did not do so then you can set it up by running the following:

$ su -c "yum install trac-git-plugin"

It also assumes that you have it installed, If you don’t you can install it using:

$ su -c "yum install git"

Creating a git repository

In order to get trac to use the repository you have to set it up first. In this howto I will set up a local repository as the trac server is on the same machine I do development work on. You can use ssh to commit to the git repository remotely. There are many guides online on how to do this, so I won’t cover it here. You can create the folder to store your git repo anywhere, by convention they usually end in .git, and to keep everything contained I’m going to store it in my trac directory.

$ cd /home/webpigeon/trac
$ mkdir repo.git
$ cd repo.git
$ git init --bare

Setting up Trac-Git

Now we have the git repo setup (although empty) we can now setup the Git Trac plugin. This process involves editing the trac configuration file in your favourite editor. The editor I’ll use it vi, but you could use emacs, nano or a graphical editor like gedit if you prefer.

$ vi conf/trac.ini

First we have to enable the git plug-in. The easiest way to do this is to locate the “[components]” section in trac.ini. I couldn’t find this in my version, so I added it. This will enable the git plug-in. If you don’t do this step you will get a lovely warning message when you use trac stating, “Warning: Can’t synchronise with repository “(default)” (Unsupported version control system “git”: Can’t find an appropriate component, maybe the corresponding plug-in was not enabled? ). Look in the Trac log for more information.”. If you have added the below and you still get the error check that you installed the plug-in back in step 1.

tracext.git.git_fs.* = enabled

Locate the “[trac]” section in trac.ini. Under this section you will need to edit repository_dir and repository_type, there are plenty of other options in this section but you can ignore them. Repository type should be set to the full path to your repository which you just created and repository type should be set to git. If your path includes spaces you should probably put it in quotes, to be on the safe side (although I’ve not tried this).

# other stuff is here
repository_dir = /home/webpigeon/trac/repo.git
repository_type = git
# ... and here

Start the trac daemon and test it works

At this point your trac should be using your git repo for it’s ‘browse code’ section.

$ tracd --port 8000 --auth="*,conf/users.digest,trac" .

You should be able to view the code at http://localhost:8000/mouse-trac/browser. If you see your code (or a message telling you “No changeset HEAD in the repository” if you haven’t pushed your code yet) then congratulations you’ve set git and trac up. The git plugin provides a number of options, but the defaults are pretty sane so I’m sticking with them, if I find any problems/interesting configurations I’ll let you know.

[footnode] Remote Git over SSH

Just a quick, “how do I set-up my client repo” as a friend asked about it. After doing the following from your local git repo, you can just use “git push” to push to your remote server (trac). The “FlapJack” is the name of the VM I host my local trac in.

$ git init
# do work ...
$ git commit -am "inital commit"
$ git remote add origin ssh://webpigeon@FlapJack/~/trac/repo.git/
$ git push origin master

Going to http://localhost:8000/mouse-trac/browser should now show you your lovely committed code.
For additional commiters/computers you can then use:

$ git clone ssh://webpigeon@FlapJack/~/trac/repo.git/

If I’ve missed anything or something doesn’t work let me know in the comments and I’ll fix it. Hope this helps.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.