Archive for April 27th, 2009

Remote Version Control with Subversion and Xcode

I split my development time between my MacBook and iMac, so I’ve been using some form of source control for the last few months (previously to that I was copying the files back and forth manually… ugh).

Up until last month I was using iDisk and Mobile Me to keep things straight. This actually works pretty well, which is why I kept using it for so long. Turn on iDisk sync and you’re given a new web-based drive on your desktop. Store your projects in there and they’ll always be up-to-date, no matter where they’re stored.

I had a few problems with this setup, thought.

  1. iDisk doesn’t handle symlinks well. This didn’t make any difference to my project, but some of the sample code I’d download wouldn’t work when it was running from the mounted iDisk volume.
  2. References to bundle resources are flakey. I never did figure out what caused this. Loading images from files worked fine, but trying to load sample data from an .XML file was completely broken, unless I stored the file somewhere besides the mounted iDisk volume. Since the file was small and never changed I got around this limitation by storing it on the Desktop on every computer I used, but it was still a janky solution.
  3. Xcode snapshots are broken. First, snapshots didn’t move from computer to computer, so if I made a snapshot on my laptop, it wouldn’t show up on my desktop. Second, the snapshots didn’t seem to persist when the project was stored on the iDisk volume.

I probably could have overcome all these issues with some effort, but why not save myself the headache and do proper SCM with subversion? Since it already has built-in Xcode support, I figured it’d be a breeze to set up. And for the most part it was.

The instructions I followed were from Jeff LaMarche and his excellent iPhone Development blog.

The helped me set up the repository, but didn’t go quite far enough. Since I’m working from two machines at the same time1, I need to be able to access my code from whichever machine I’m on. Most tutorials out there seem focused on either setting up local repositories, or setting up shared repositories on OS X Server, neither of which quite give me what I need.

Creating the Shared Repository

Since subversion is installed in OS X by default, setting up the repository is simple. These instructions are ripped from from Jeff’s blog. Open up Terminal and run the following commands.

cd /Users/Shared
mkdir subversion
cd subversion
mkdir HelloWorld
svnadmin create HelloWorld
chmod -R 777 HelloWorld

Setting up Remote Login in OS X

In order to securely access your repository remotely, you’ll need to turn on remote login in OS X. Navigate to the Sharing tab in Preferences and turn Remote Login on.

While you’ve got preferences open, find out what your computer’s local hostname is, you’ll need this later. You can find it in the text towards the top of the Sharing window, mine is Grover-Cleveland.local. By using this name to access your repository, you will be able to access the source even if the IP address of the server changes and you should be able to access it from outside your LAN if you’ve got Back to My Mac enabled with Mobile Me (I haven’t tested this yet).

Accessing the Shared Repository in Xcode

Open up Xcode. Hit Command-, to open Preferences. Navigating all the way to the right, you should see an SCM window. Click the “plus” sign at the bottom window to create a new repository. Give it a name, the name doesn’t have to be the same as what you set up earlier. Hit OK and create the new repository. In the URL box type the path to your subversion repository like so:

svn+ssh://username@your-computer.local/Users/Shared/subversion/HelloWorld

where username is your current login and your-computer.local is the address of your computer that we located earlier. For your first connection you’ll be prompted to add the SSH key and Xcode will ask to use your confidential information. Go ahead and let it, and you’ll be set!

Read through the rest of Jeff’s post to get some more details on using Subversion and Xcode, or read Apple’s documentation if you’d really like to go in-depth.

After a few weeks of using this system, there is no doubt that it makes the process of working on code from two different machines much more seamless. The one problem I’ve been having, and I’d be grateful if anyone knew a solution to this, is that the Commit All Changes… command will not work for me. I’ve got to go through, select all the modified files and commit them in batches. In order to commit the .xcodeproj file I need to use the SCM Results command to browse inside the .xcodeproj package and manually commit the files it contains. Vexing…

Anyway, I hope this helps some people!

Edit: I’ve had some problems with the following error, Error: 155005 (Working copy not locked; this is probably a bug, please report). After ignoring it for a few months and finally trying to figure out what’s wrong, I realized that you need to delete the “Build” directory from your repository after you delete it. After this you should have no problem doing full project commits from the menu bar.

Footnotes:

  • Now you know what I’d do if I had a million dollars