Xcode 3 Feature: Version Control Repository Access

Xcode 3 adds support for configuring and viewing version control repositories. With Xcode 3 you can import projects and checkout files inside Xcode. All you have to do from the command line is create the repository. This article will show you how to take advantage of Xcode 3′s enhanced version control capabilities. One word of caution. If you hated Xcode’s version control support in earlier versions of Xcode, you’ll want to stick with the command line. Xcode 3 repository features are a little flaky.

Xcode supports Subversion, Perforce, and CVS. I’m going to focus on Subversion because Mac OS X 10.5 ships with Subversion, and CVS seems to be losing popularity with developers.

Step 1: Create the Repository

If you haven’t done so already, open the Terminal application and create a repository by running the svnadmin create command. I have detailed instructions you can read (PDF) on creating a repository if you need them. One thing to note is that because Mac OS X 10.5 ships with Subversion, you don’t have to install it, and in Mac OS X 10.5 Subversion is in /usr/bin instead of /usr/local/bin.

Step 2: Configure Your Repository

Before you can take advantage of Xcode’s repository features, you must configure your repository in Xcode. Launch Xcode and choose SCM > Configure SCM Repositories. A window similar to the following figure will open:

Click the + button to add a repository. You will be asked to name the repository and specify what version control system you’re using.

Now you must specify the URL for the repostiory. A local repository’s URL starts with file:// and follows with the path to the repository on your hard drive. If the path you specify does not show up in the Path field, you’ll have to enter the path to your repository in the Path field.

I have not tried configuring a remote repository, but Xcode’s repository configuration window has Host, Port, User, and Password fields. I assume you would fill these fields to configure a remote repository. If you’re going to connect to a remote repository using SSH, click the SSH tab in the window.

Click the OK button, and you’ve configured the repository.

Step 3: Open the Repositories Window

Choose SCM > Repositories to open Xcode’s repositories window, which you can see in the figure below. The repositories window lets you examine the directories inside your version control repositories. Select a repository from the list on the left to examine that repository’s directories. Some things you can do from the repositories window is import projects, check files out of the repository, create directories, move directories, and delete directories.

If you’ve created a fresh repository, I strongly recommend creating a directory inside the repository and storing your projects inside that directory. In my experience using Xcode’s repository features on a fresh repository, I noticed Xcode let me add only one directory to the root of the repository. Any additional directories I tried to create were created inside the first directory I created. This is why I recommend creating a directory, naming it something like Projects, and import your individual Xcode projects into the Projects directory.

If you have a repository that you’ve been using for some time, you’ll see directories inside the repository root for the projects you have in your repository. If you try to add or import a directory to the repository root, the directory will get added to one of the subdirectories inside the root. There are two solutions.

First, you can fire up Terminal and create a directory from the command line using the svn mkdir command. I had difficulty getting my created directory to appear in the repositories window, but after a few attempts I did get the directory to appear. Second, you can create a fresh repository for your new projects, add a Projects directory to the new repository, and use the new repository for any new projects you want to place under version control.

Step 4: Import the Project

Before importing a project, you must create an Xcode project and move the project’s files to a folder. If you follow Subversion conventions, you’ll go to your project folder in the Finder and add three folders named branches, tags, and trunk. Move your project files to the trunk folder.

To import a project, select the directory in the repositories window where you want to import the project (If you’re following along, this will be the Projects directory you created in Xcode’s repositories window) and click the Import button. An Open File dialog opens. Navigate to your project folder, type a comment, and click the Import button.

There should be a directory inside the Projects directory with the name of your project. Inside the project name directory should be the branches, tags, and trunk folders. The trunk folder should contain your project’s files. If these folders don’t show up, click the Reload button to refresh the repositories window.

Step 5: Check Out Files

After importing a project, you want to check out the source code files in your project. Select your trunk folder in the repositories window and click the Checkout button. A dialog box opens asking you where you want to store the checked out files on your hard drive. Navigate to where you want to store the checked out files. Normally you will store the checked out files in a folder inside your Xcode project’s folder. Click the Checkout button. You’ll be asked if you want to open the Xcode project. Open it if you want.

Step 6: Turn on Version Control

Although you’ve imported a project and checked out files, you still have to tell Xcode to use version control for the project you imported. Open the Xcode project (the project file you checked out in Step 5, not the original one you created in Xcode). Select the name of the project from the Groups and Files list and click the Info button on the project window toolbar. An information panel will open. Click the General button in the information panel. Choose your repository from the SCM Repository pop-up menu, and you’re ready to use version control with Xcode in Mac OS X 10.5.

Comments (11) | Trackback

11 Responses to “Xcode 3 Feature: Version Control Repository Access”

  1. Anonymous says:

    Thanks a million Mark! I found this to be very helpful.

  2. Tom says:

    Mark, thanks for the clear instructions. I followed them but hit a snag at step 6: in the SCM repository pulldown menu, my new repository is listed, but it’s gray and unselectable. Any suggestions for what I might have done wrong?

  3. Tom says:

    Never mind, found my own answer. Apparently this is a common problem. For my simple application, the easy solution was to move the .xcodeproj file for the project down into the “trunk” subdirectory along with the source code. Then basically all work gets done inside “trunk”, and Xcode’s “build” directory gets created there. There are more sophisticated discussions of this problem and solutions on other blogs (e.g. “I Should Be Coding”).

  4. Mark says:

    For anyone having the new repository grayed out in the SCM repository menu, a grayed out repository means the project file has not been checked out of the repository. When you check out an Xcode project (Step 5), there are two copies of your Xcode project: the one you created in Xcode and the one you checked out. Make sure you open the Xcode project file you checked out, not the project file you created in Xcode.

  5. Anonymous says:

    Thank you for your writings. Still have some questions.
    How do you handle a project with a set of files from a second project?

    How do you create tag’s and branches?

    Thank you

  6. Mark says:

    I’ve never tried to import a project that contained files from a second project. If the import doesn’t work right, I can think of two possible solutions. If you want to place the second project under version control, import that project and check out its files. If you don’t want the second project to be under version control, make copies of the files that belong to the first project and add those copies to the first project.

    You can’t create tags and branches in Xcode. You must launch the Terminal and run the appropriate commands. If you do a Google search for Subversion, the first result is the Subversion official site. On that site is an online book that contains a chapter on merging and branching that also covers tags.

  7. AndrewC says:

    Is it really necessary to checkin and checkout the project?

    You should just be able to set up an empty repository folder and create a new project in that folder and simply add all the files to the repository from there.

  8. Mark says:

    Andrew,

    In my experience, Xcode’s SCM features won’t work unless you import the project and check out the files in the project.

    You can try what you suggested (create an empty repository folder, create a project in that folder, and add the files to the repository). If it works, let me know. It would be nice to know that you don’t have to import a project to use Xcode’s SCM features.

  9. Nick says:

    Cheers for this.

  10. Anonymous says:

    i'm gonna make my own site about it

  11. Anonymous says:

    Can anyone recommend the top performing Remote Management tool for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central system network
    ? What is your best take in cost vs performance among those three? I need a good advice please… Thanks in advance!

Leave a Reply

Powered by WordPress