Using CVS with Xcode 3.1 on Leopard

xcode.jpg

One of the things that has historically been a problem with NeXTSTEP/OPENSTEP and now Mac OS X development projects and source control is the fact that on all the operating systems, the bundle concept exists and complicates CVS considerably. The bundle is nothing more than a directory that's treated as a single entity. The app, the nib, the rtfd... all these are really directories on the filesystem and yet the OS thinks of them as single, indivisible entities. So when CVS goes to make a CVS directory in one of these bundles, and then the tool (such as InterfaceBuilder) saves a change, it overwrites the entire directory - destroying the CVS directory within the bundle.

With the recent editions of Xcode (from the old ProjectBuilder) the source code control has been built-in. However, I've been very gun-shy to use it for fear of not getting anything done because of these issues. So it was a very anxious time for me today when I tried to get my first Xcode 3.1 project put into my home repository.

Since the repository was already created, and running on Mac OS X 10.4 (Tiger), I thought if it were going to work at all it should work in this environment. So I did a little Googling on this and found a page that walks through this for Subversion, but not CVS. I figured that if I backed everything up, I'd be set. So I dove in.

Configuring Xcode for Your Repository

The first thing to do is to have a repository, since I had one, and it was already running on a pserver I'd set up ages ago, it seemed like I should be set to go. What confused me for a little bit was the fact that Xcode was going to allow me to configure the root of the repository and therefore view all the projects I've placed in that repository. Very nice. In order to get there, however, you need to tell Xcode how to connect to your repository.

Select SCM -> Configure SCM Repositories and then click the '+' button at the bottom of the list to add a new repository. Once you give it a name and a type, you'll get an appropriate dialog box where you can enter all the data for the repository Xcode will need. As a nice little bonus, as you fill in the components, Xcode builds up the CVSROOT (for those that are familiar with this, it's a real lifeline) and so you can see each component going into the CVSROOT as you enter it into the dialog. When it's all filled out, Xcode will automatically verify the connectivity (another amazing piece of work) and then you can click "OK" to save everything.

At this point you have the repository configured with Xcode. Now you can look at it by selecting SCM -> Repositories and then the one you just added will be on the left and it's contents in the finder-like view on the right. You can look at everything you've already put into your repository (for those of us that used existing repositories, this is really a place to give a wonderful sigh of relief.)

Xcode Preferences

Import Your Project

Once you have a project ready to import, simply select where you want the root of your new project to sit, and click on the Import icon in the Repositories window. Xcode will then ask you what to import - navigate to the root of the project directory and give it a nice comment. Xcode will indicate in the bottom pane of the Repositories window what's happening and in a few minutes, you're all imported.

Repositories

Check-Out Your Project

As with all other CVS imports, save the old project file by renaming it, or tar-ing it up and saving it off someplace, and then from the Repositories window select the project you just imported and click on the Check Out button. Xcode will ask you where to put this, and you can navigate to the directory you want it to be placed. Click 'OK' and Xcode will do the checkout. As a wonderful feature, it's going to ask you to open the project in Xcode when it's done. Say 'Yes', as we need to do one last thing before we're done.

Enable SCM on Your Project

Now you need to navigate in the 'Groups and Files' list to the name of the project (typically the first thing in the list) and then click on Info to pull up the main project info window. Navigate to the 'General' panel and then at the bottom choose the repository from the SCM list and you'll notice the GUI shifts a bit to place the CVS status next to each file. At this point, you're ready to go. The SCM menu is now greatly expanded and using SCM in Xcode is very simple.

Project 201CPotentials201D Info

You can do diffs... additions... moves... all the things you'd normally do, and with CVS, Xcode is smart enough not to blow away the directories of the bundles and so things get versioned properly. It was easy... but very nerve racking for my first time since the old days. In the future, I'll tell people to do it earlier. Much earlier.