Tutorial: Subversion on Mac OS X

In my professional role as a software developer, I have become highly dependent on revision control software. It's just about impossible to manage a software project of any size involving more than one person without some system to keep track of the myriad files involved. A good version control system allows multiple developers to work on the same code without worrying (too much) about overwriting up each others changes. It provides a central file repository, so you always know where to go for the "master" copy, and is also simple to back up. And perhaps most importantly, it saves a history of every change you make to the file. So if you ever need to get a copy of some document as it existed last Friday, it's right at your fingertips.

Technorati Tags: , , ,

Understandably, our entire process of writing and releasing software at work is built around version control. We use hooks to automatically run a test suite every time new code is checked in to a particular place. When we're ready to release a new version, we "tag" the repository with a build number so that we will always be able to get exactly that version of the code, regardless of what changes happen later. I use version control a hundred times a day at work. It would be nearly impossible to do my job without it.

So why don't I use it at home?

Just about everything I do on my computer at home could benefit from version control. I work on personal software projects, I write, I build websites that have HTML and graphic files. Sure, I'm only one person, but I do use two separate computers. Wouldn't it be nice to not have to worry about which has the most current copy of a particular project? It would also be great to have one spot for some configuration and reference files so that, when I need one on the road, I don't find out that it's only on the desktop at home. Version control software can do all of that.

So I decided to install subversion on my PowerMac running Mac OS X Tiger. Turns out it's actually quite easy, so I thought I'd share it with you here.

This is just a subversion installation tutorial. If you want much more in-depth information on subversion, check out the totally cool free book, Version Control with Subversion (or get the paper version).

Martin Ott has graciously made available installation packages for subversion to save us from the grief of building and installing the necessary components ourselves. I downloaded and ran the 1.20 RC 4 package, which worked perfectly for me on OS X 10.4.

There are a couple necessary post-installation tasks, though. Subversion was installed to the /usr/local/ directory, so you'll need to adjust some settings to find it by default. First, if you use "man" for help with your command line tools, edit the /usr/share/misc/man.conf file and add this line:

MANPATH /usr/local/man

This will allow you to access subversion's newly installed manual files.

Second, if you'll be running subversion from the command line, and if it's not already, you'll need to add /usr/local/bin to your PATH. You'll also need to set a default editor to use for comments when committing files to the repository. Edit (or create) the file at /Users/username/.bash_profile and add this line to the bottom of the file:

export PATH=$PATH:/usr/local/bin
export SVN_EDITOR=/usr/bin/vi (or your editor of choice)

The next Terminal window you open will use this updated path. Congratulations! You have subversion installed.

Now what?

Well, before you can actually start using it, Subversion needs to have a repository configured. This is the central location where all of your files will be stored behind the scenes -- you'll never work with these file directly. I want mine to be stored at /usr/local/svn/. Create it by running this commnad:

svnadmin create /usr/local/svn

If you are unable to create this directory due to permissions, create it manually and assign ownership to yourself:

sudo mkdir /usr/local/svn
sudo chown username:username /usr/local/svn

Update: If you do need to create the directory manually, you will have to run the "svnadmin create /usr/local/svn" command again to initialize the repository.

You'll need to set up some basic directory structure to your repository. Version Control with Subversion recommends three top level directories -- branches, tags, and trunk -- to support branching later. Everything you add and work with will initially go in "trunk". Create the basic structure in the /tmp directory and import it:

mkdir /tmp/personal
mkdir /tmp/personal/branches
mkdir /tmp/personal/tags
mkdir /tmp/personal/trunk
svn import /tmp/personal file:///usr/local/svn -m "initial import"

Once this is done, you can delete the /tmp/personal directory.

Next, prepare the space for the working copy of your repository -- this is where you will directly access your files. Mine is at /Users/username/personal/.

cd
svn checkout file:///usr/local/svn/trunk personal
cd personal

Now you have a working copy of your repository. You can create files in your "personal" directory. When you want to commit them to your repository, run

svn add filename

then

svn commit filename -m "A personal log message goes here"

from the command line.

If you'd like to avoid the command-line heavy process, check out scplugin, which allows you to integrate subversion directly into the Finder. Here's a tutorial to help you install scplugin. (disclaimer: I haven't tried it yet, but I'll let you know how it goes once I do).

So that's it! You now have subversion running locally, giving you all the benefits of version control at home. My next subversion-related tutorial will be on how to run it as a service and access your repository from other computers. In the meantime, if you're handy with Unix, you can get the basic idea from running:

svnserve --help

You'll then need to run the "svn checkout" command from the other computer with an "svn://server.hostname/" argument instead of "file:///..."

Until, then, enjoy! Please post a comment here if this has been useful, or if you're having trouble with some of the instructions.

(Originally posted on Distracto)

by frank on Jul 1, 05 11:46 AM

Trackback Pings

TrackBack URL for this entry:
http://www.macpot.com/cgi-local/mt/mt-tb.cgi/60