So I’ve recently started my first foray in to programing a larger Rails project and need a version/source control mechanism to handle maintaining it with my collaborators. We choose to go with Subversion, and Trac. I instantly fell in love with version control! Now to you veteran programmers out there, you probably know all about this, but I’m a n00b so please excuse my excitement. So I wanted to find a way to do version control on my own machine for my smaller personal projects, and ideally use some slick interface to be able to browse the changes. I had recently read in one of the TextMate users mailing list (which I obsessively read) about Mercurial, someone was having problems with the Subversion bundle, and someone suggested if their needs were lightweight they should consider Mercurial (for which there is also a TextMate bundle). So I decided to check it out.
For those of you who don’t know about Mercurial (a.k.a. hg), It’s a distributed version control system (for a comparison on version control systems see Wikipedia), which differs from SVN’s centralized method. SVN has you commit changes to a central repository and you handle any conflicts between your copy and the current revision then. With hg you commit changes on your local machine, and then eventually you may combine it with another copy of the repo. So if you figure out a way to solve a problem that someone else is having and you’re talking about it, you can just “push” your version to them, and then they can get your fix. There’s more to it than that, but if you want more go to the Mercurial web site. So it works great, since your local copy is a full set of changes, as a personal version control system. Then all you need is a nice way to browse the revision history, in comes Trac. Now I know you could use a standard diff file/tool, or the built in web interface, but I hate the way those look, and I love the way Trac looks, just a personal preference. And lucky for us Trac has a new Mercurial plugin!
So here we are at the meat of this entry, how to set it up on your Mac. What you should already have installed is OS X 10.4 (aka Tiger), and DarwinPorts (which it’s self requires the installation of Xcode tools from Apple). Once you’ve got that set up you’re ready for my instructions:
Install the following “ports”. Use the Terminal application and the commands should look like this:
sudo port install python24
and allow any dependencies they might require:
python24
mercurial
sqlite3
py-docutils
py-setuptools
py-sqlite
clearsilver
SilverCity
subversion
- Make sure your PATH is set up right in your
.profile file in your home directory, test this by entering hg version in the terminal.
Set up a Mercurial repository (Also see Mercurial wiki):
- Set up a .hgrc file in your home directory (~/). See Mercurial wiki hgrc page
- Navigate to your projects directory in the terminal shell.
Create the repository:
hg init
Set up your .hgignore file to handle files you don’t want under version control. See Mercurial wiki hgignore page
Add your project files to the repository:
hg add
Commit your project:
hg commit
Install Trac (you can always see the Trac wiki for help)
- Download Trac 0.10.x tar package
- Extract the contents of the archive.
- Navigate to the top of the directory created by the extraction.
Enter the following command:
sudo python ./setup.py install
A good idea is to test that your PATH is working by enter trac-admin help at the command prompt
Install the Mercurial plugin for Trac:
Get the latest code for the plugin via the Subversion repository:
svn co http://svn.edgewall.com/repos/trac/sandbox/mercurial-plugin
You can execute this anywhere on your hard drive.
Run:
cd mercurial-plugin
Run the following command to make the “egg” for the plugin:
python setup.py bdist_egg
Run:
cd dist
To install it globally for your install of Trac:
sudo easy_install TracMercurial-0.10.0.2-py2.4.egg
To activate it add this to your global trac.ini file (it should exist in this directory: /opt/local/Library/Frameworks/Python.framework/Versions/2.4/share/trac/conf, you may have to create it as it may not exist yet):
[components]
tracvc.hg.* = enabled
Set up a Trac project
Run a command like this to set up your Trac project (the path part should be the path where you want the Trac files to go, not where your hg repo is):
trac-admin ~/Sites/myproject initenv
It will walk you through a series or prompts.
- When it asks for type of repository type:
hg
- It will also ask for the path to the repository give it the full absolute path that you created your repository in before (see step 3).
Open the trac.ini file for the project:
cd ~/Sites/myproject/conf/
open trac.ini
Add the following lines to the end of the file:
[hg]
# -- Show revision number in addition to the changeset hash
show_rev = yes
# -- Changeset hash format
node_format = short
# hex: Show the full SHA1 hash
# short: Show a shortened hash for the changesets
You may wish to further customize your trac.ini file, if so see the Trac wiki page on it.
Make changes, commit changes, run Trac Standalone Server, repeat:
- Make changes to your project files.
- Commit the changes, you can either do:
hg commit. Or you can use the Mercurial bundle for TextMate.
Run the Trac standalone server, by entering this command in the terminal:
tracd --port 8000 ~/Sites/myproject
Enjoy!
Tags: version control, Mercurial, Trac, MacOSX, web development, programming, howto