Setting up Mercurial and Trac for personal version control on your Mac

Wednesday, March 7th, 2007 @ 12:03 am | Mac, Web Development

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:

  1. 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
  2. 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.
  3. Set up a Mercurial repository (Also see Mercurial wiki):

    1. Set up a .hgrc file in your home directory (~/). See Mercurial wiki hgrc page
    2. Navigate to your projects directory in the terminal shell.
    3. Create the repository:

      hg init
      
    4. Set up your .hgignore file to handle files you don’t want under version control. See Mercurial wiki hgignore page

    5. Add your project files to the repository:

      hg add
      
    6. Commit your project:

      hg commit
      
  4. Install Trac (you can always see the Trac wiki for help)

    1. Download Trac 0.10.x tar package
    2. Extract the contents of the archive.
    3. Navigate to the top of the directory created by the extraction.
    4. Enter the following command:

      sudo python ./setup.py install
      
    5. A good idea is to test that your PATH is working by enter trac-admin help at the command prompt

  5. Install the Mercurial plugin for Trac:

    1. 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.

    1. Run:

      cd mercurial-plugin
      
    2. Run the following command to make the “egg” for the plugin:

      python setup.py bdist_egg
      
    3. Run:

      cd dist
      
    4. To install it globally for your install of Trac:

      sudo easy_install TracMercurial-0.10.0.2-py2.4.egg
      
    5. 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
      
  6. Set up a Trac project

    1. 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
      
    2. It will walk you through a series or prompts.

    3. When it asks for type of repository type: hg
    4. 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).
    5. Open the trac.ini file for the project:

      cd ~/Sites/myproject/conf/
      open trac.ini
      
    6. 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
      
    7. You may wish to further customize your trac.ini file, if so see the Trac wiki page on it.

  7. Make changes, commit changes, run Trac Standalone Server, repeat:

    1. Make changes to your project files.
    2. Commit the changes, you can either do: hg commit. Or you can use the Mercurial bundle for TextMate.
    3. Run the Trac standalone server, by entering this command in the terminal:

      tracd --port 8000 ~/Sites/myproject
      
  8. Enjoy!

Tags: , , , , , ,

One Response to “Setting up Mercurial and Trac for personal version control on your Mac”

  1. links for 2007-06-07 « Bloggitation Says:

    [...] Setting up Mercurial and Trac for personal version control on your Mac (tags: scm mercurial mac sysadmin) [...]

Leave a Reply