SVN on Mac OS X

Mac OS X    2008-11-04

It's a few years old, but this article on downloading and installing svn for OS X is still the best and most useful:

Building Subversion (SVN) on Mac OS X [Hive Logic]

Installing is the hard part - once you've got installed, it's just a few easy steps to get your code into source control:

1) create a local repository
2) import your code into that repository
3) check the code out to a working directory

1) Create the repository:

It doesn't really matter where, just put the repository somewhere on your local system that makes sense to you. Personally, I keep all of my code in a folder under my home directory, in a structure that looks a little like this:

/Users/barbara/Code/
	myrepository/
	firstproject/
	secondproject/

So once you've decided where to put the repository, switch to that folder and run 'svnadmin':

cd /Users/barbara/Code/

svnadmin create myrepository

2) Import code into the repository:

The svn import command requires two arguments - PATH and URL.

In this example, the PATH is 'firstproject', where the code already lives, and URL is the place in the repository where it should be stored (with 'file://' prepended to the filepath):

svn import firstproject file:///Users/barbara/Code/myrepository/firstproject -m "new import"

You'll see something like:

Adding         firstproject/file1.py
Adding         firstproject/file2.py
Committed revision 1.

3) Check out the code:

One proviso here - in an ideal world, I would have set up my repository first. But I had already written a lot of code before I got around to this, hence the need to move all the original code out of the way first, then check it out again.

rm -rf firstproject/

svn co file:///Users/barbara/Code/repository/firstproject

A    firstproject/file1.py
A    firstproject/file2.py
Checked out revision 1.

A few extra useful svn commands:

cd firstproject/

svn log

This will output something like:

------------------------------------------------------------------------
r1 | barbara | 2008-11-04 11:10:42 -0800 (Tue, 04 Nov 2008) | 1 line

new import
------------------------------------------------------------------------

And

svn info

Will give you something like:

Path: .
URL: file:///Users/barbara/Code/myrepository/firstproject
Repository Root: file:///Users/barbara/Code/myrepository
Repository UUID: 419c4dc3-c15z-0560-ab63-aa4cc4fbe4a1
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: barbara
Last Changed Rev: 1
Last Changed Date: 2008-11-04 11:10:42 -0800 (Tue, 04 Nov 2008)

If you've made any changes to files, run status to see what needs to be checked in:

svn st