How to setup an SVN repo in Xcode

If you purchase a component from the Dr. Touch’s Parts Store you will receive a quick start guide which includes the access details to the Subversion repository that keeps my code. The address of the repository uses HTTPS protocol, which confuses some people into thinking that they could use a browser to download the files.

That’s why I made this video showing how to properly set up your Xcode to get the source for any part onto your harddisk.

The advantage of following this guide is that you end up with a “working copy” of the contents of the repository. That means that you can simply pick “SCM – Update Entire Project” and you get your copy updated to the latest version.

There are generally several methods how you could add external code to your own project, besides of simply copying it. The problem with just copying is that it’s quite hard to keep all the individual copies of a framework updated in all of your projects.

In my case I am continuing development on most of my components if I add them to one of my own apps, but I don’t want to have to make all additions that I put into the new project into the component project a second time. Development is boring if you have to repeat steps. Surely there has to be a method to have the updates stream back from the app project to the component project.

In fact, there is. The technique to use is called …

External SVN References

You can instruct your Subversion client to treat a specific folder as coming from a different SVN Repo. This is quick to do on the command line, some Subversion clients offer this as well. Xcode does not, yet. I thought that this “Multiple Project Roots” feature was supposed to achieve this, but if I set up a folder coming from a different repo I can no longer “Commit Entire Project”.

Open Terminal and navigate into your project root folder (or any location where you want such an external reference to be). Then type the following, the first being the name of the new folder, the second being the SVN URL. Note that spaces in the URL need to be URL-encoded. Don’t forget the period at the end telling SVN that you mean the current folder.

Alternatively you can also uses propedit, if you set up the editor to use for SVN. Though this means that you have to know your way around a Unix text editor like vi.

export SVN_EDITOR=vim
svn propedit svn:externals .

If you now perform an Update then SVN will create a directory with the name DTChartView and will check out the contents of the passed SVN URL into it.

From here on forth you can work with these files just like with any other files, for example add them to the Xcode project in which you want to use it. Changes are treated just the same. Local modifications get an M, available updates on the server are marked U, etc.

Only thing I noticed is that “SCM – Commit Entire Project” does not commit contents of external SVNs at the same time. Whereas a “SCM – Update Entire Project” seems to get all updates globally. As usual you can commit individual files or multiple files regardless from which repo they stem.

So if you tend to modularize your code and find that you keep reusing and refining your core toolbox, then this technique might just be what you need because this way you can update your tools while working on another app.

Bug!

There also seems to be a bug in Xcode dealing with external references that are on a different server than where your project is residing. The above mentioned steps worked without problem while I was moving around on the same server. But as soon as I had a project on a different server than mine, Xcode started to be unable to authenticate to my own server when it tried to refresh. I kept getting “Could not authenticate to server: rejected Basic challenge”. The log file on my SVN server told me “Password mismatch”. One theory I pursued for some time is that I have the same user name on both servers, but different passwords. Maybe Xcode got stuck sending the wrong one. Who knows…

At the same time the command line tools as well as the Versions svn client that I was trying out did not have this problem. That’s how I judge this to be some Xcode weirdness. But for me personally this is not a problem because I tend to keep all my source code on the same server.