There’s a fossil that’s trapped in a high cliff wall.


A Simpler Approach to Subversion and Xcode

24 February 2011

I’m no expert on Subversion, but I have learned over time how to at least not wrestle with it quite as much.

Xcode’s integration with Subversion is generally good, and the workflow is simple. I modify a file, save it, and commit it to my repository. If I need to step back to see an earlier version, Xcode provides simple graphical tools that let me see what I’ve changed and revert to the older version if I want. Except for the occasional glitch (deleting and renaming files are the main culprits), I’ve not had many problems.

It’s the things that I rarely do that take far too long, and creating and using a new repository is at the top of the list. For the first few projects, I followed the directions in Fritz Anderson’s excellent Xcode 3 Unleashed, available at Amazon. Fritz starts by creating the directory for the repository and creating the repository in the Terminal, then moves to setting up the rest in Xcode. The main problem is that the graphical interface in Xcode 3 is fiddly in setting up the standard trunks, tags, and branches directories, and for importing the project. The second problem is that Fritz describes much of what can go wrong, and that’s great for when you’re just starting, but it hides how simple the process can be once you understand the basics. I needed a simple set of commands for a simple but rare task.

I later discovered Mike Mason’s fantastic Pragmatic Version Control Using Subversion. It’s great as both a tutorial and a reference, a hard balance for most authors. Mike emphasizes using Subversion on the command line, and that makes it clear that graphical interfaces can make simple tasks too complicated. His book pointed the way for the simple set of commands.

I now set up my repository in the Terminal, and use Xcode to check out and modify a working copy. This approach uses the Terminal where it is simple (setup) and Xcode where it is simple (daily use).

To set up the repository, I change directories to where my repositories are stored (Subversion), create a directory for my new repository (newProject), and create the repository.

sholland$ cd /Users/sholland/Documents/Subversion

Subversion$ mkdir newProject

Subversion$ svnadmin create newProject

Next, I change directories to where my project currently resides (myProject), and then import it into the new repository.

Subversion$ cd /Users/sholland/Desktop/myProject

myProject$ svn import -m "Initial import of project" file:///Users/sholland/Documents/Subversion/newProject/trunk

The import will automatically make the standard trunk directory. The last steps are adding the standard branches and tags directories:

myProject$ svn mkdir -m "Create tags directory" file:///Users/sholland/Documents/Subversion/newProject/tags

myProject$ svn mkdir -m "Create branches directory" file:///Users/sholland/Documents/Subversion/newProject/branches

That’s all you need to do in Terminal. From here, you can launch Xcode, tell it about the repository, check out a working copy, and you’re ready to go. Once you see that everything works, you can delete or archive the original myProject directory.

As you can see, I keep my repository on my computer, but you could easily modify this workflow for a remote repository, largely by changing file: to svn:. When I first learned Subversion from tutorials, I’d confuse the original (unversioned) project, the repository, and the new (versioned) project. Here, I use different names so that you can keep them straight, but in practice, I give them all the same name. Finally, if you’re setting up your first repository, be sure to check out Fritz’s more detailed instructions for making Subversion work well with Xcode. In particular, he includes directions for making Subversion not keep track of files for which you don’t need backups.