Using Subversion With XCode
Source Code Management Made Easy
24 September 2004 Justin Williams Skip to comments
30 Comments
(
Closed)
### Introduction Have you ever been working on a project in Xcode, taken a direction in the code, and wished you hadn't? You sat there and just wished you could go back to the way your code was three days ago before you decided that bad idea was a really good one. Maybe you work in a team and were frustrated when your coworker was working on the same file you were and saved over the three hours worth of changes you had just made. Both of these issues would be nonexistent if you used some sort of version control in your coding projects. Version control is taken care of by some sort of source code management system. These applications keep track of version history, releases, code differences, and many other features. When I wrote my article on using XCode with CVS, I made a promise to a few readers that when Apple released a version of XCode that supported Subversion, I'd give those users a tutorial of their own. Well, Apple released XCode 1.5 a few weeks back, and it includes support for Subversion repositories. CVS (Concurrent Versions System) has been the de facto standard for version control for many years. The problem with CVS is that CVS is starting to show its age. CVS, for example, sends passwords as cleartext and has only limited support for binary files. Subversion 1.0 was released on February 23, 2004 and hopes to eventually become the successor to CVS. While the 1.0 branch is only a few months old, the Subversion project began back in 2000 at Collabnet. While the project was begun at the company (and is still funded by), Subversion is an open source project that is being worked on by thousands of intelligent developers around the world. Subversion has all of the features of today's CVS implementation, and builds on it with the following:This article covers the basics of installing and configuring the Subversion source management system and integrating it with Apple's XCode development environment.
- The ability to add, delete, copy, and rename files and directories.
- Integration into Apache allows for WebDAV connections.
- Plugin Support.
- Versioned Metadata.
- Full binary support.
Subversion Installation
Installation of Subversion is relatively simple. For those only wanting a client, we are going to install Martin's client binaries. You can grab these from his homepage. Launch the installer, walk through it, and you are done. The binaries are installed in /opt/subversion, but symbolic links are setup in /usr/local.
In the Terminal, edit ~/.bash_profile so that the PATH variable reads like this:
PATH="/usr/local/bin:/usr/local/subversion/bin:$PATH"
export PATH
Save the file, close your terminal, and open a new window. You should now be able to execute all the commands in subversions bin directory without typing their full path.
If you are just going to access a remote Subversion repository, and are not interested in setting up a local one on your Mac, skip down to the section on using your repository in XCode.
Next, mount Wilfredo's public iDisk from the Finder or using Apple's iDiskUtility. His .Mac name is wsanchez. Grab the following files from his iDisk and install each of them.
- BerkeleyDB
- Expat
- Libxml2
- Neon
- SWIG
- APR
- APR-util
- Apache2
- Subversion
- import: The import command will import a new project into the Subversion repository.
- checkout: The checkout command creates a local copy of your Subversion repository on your system.
- svn checkout http://svn.maczealots.com/myapp/trunk
- update: Get the latest updates to your working copy of the repository. If someone else is working on your project, you will most likely want their latest changes to the code base.
- svn update
- add: Add a file to a repository.
- svn add source.m
- delete: Delete a file from the repository.
- svn delete source.m
- copy: Create a duplicate of one file as another.
- svn copy source.m source_copy.m
- move: This will rename the original file to a new name.
- svn move source.m source_copy.m
- status: The status command will detect all file and tree changes you have made to your repository.
- svn status
- diff: The diff command shows you exactly what you have changed in each file in your respository.
- svn diff
- revert: If you find out that you have really screwed up a file, and want to go back to the way things used to be, revert is what you need to use.
- svn revert source.m
- conf
- A directory containing configuration information.
- dav
- This directory is used by Apache for WebDAV sharing of the repository's information.
- db
- This houses the database tables that hold the Subversion filesystem.
- format
- The version number of the repository layout.
- hooks
- This directory holds hook script templates. A hook is a program triggered by some sort of repository event.
- locks
- A directory for the locking data. It is used to track who is accessing the repository.
- README.txt
- This reminds you what you are in a Subversion directory and to not manually poke around.
As a note, if you are using an existing project, delete the build directory from inside the project before you import into the repository. We really don't want to have those files replicating in our repository because they take up unnecessary space. Let's import a project from the Terminal. Unfortunately, XCode doesn't support importing new projects yet. This should all be typed in on one line:
svn import ~/Development/projectA http://localhost:8800/ \svn/projectA/ --message "Initial repository layout" You will get an output that looks like this.
Adding projectAWe are going to need to check out a copy of our application from the Subversion repository. If you imported an existing XCode project in the step above, you are going to want to put that somewhere else for storage, because it is no longer that useful to us. To checkout a copy of our application, run the following commands: cd ~ svn checkout http://localhost:8800/svn/projectA/trunk projectA This will create a projectA directory at the top of your home directory. If you want to store the project somewhere else, change the first line above to be the path where you want the folder to go.
Adding projectA/trunk
...
Adding projectA/branches
Adding projectA/releases
Apache Configuration
We need to edit the Apache2 configuration files so that it plays nicely with both Subversion and MacOS X's default Apache 1.3 installation. Open /usr/local/apache/conf/httpd.conf in your text editor of choice making sure you are the superuser (root). Add the following line at the bottom of the section of LoadModule statements: LoadModule dav_svn_module modules/mod_dav_svn.so Next, we need to change the default user from nobody to www. Search for the line 'User nobody' place a # in front of it and add 'User www' below: # User nobody User www After that we need to put Subversion and Apache2 on a different port than the MacOS X web server. By default, it uses port 80, so we will go with port 8800. You can pick any port you want as long as its not a port in use by another service. Here is a relatively good list of ports in use. # Port 80 Port 8800 Finally, before we save the file, we need to setup a new location so that Apache knows where to find our Subversion repository. Add the following line towards the bottom of the httpd.conf file. <Location /svn> DAV svn SVNPath /Users/Subversion AuthType Basic AuthName "Subversion Repository" AuthUserFile /usr/local/apache/etc/svn-auth-file Require valid-user </Location> We will be using WebDAV to access the repository. WebDAV is a set of extensions to the HTTP protocol which let users edit and manage files on a remote web server. iDisk runs off the WebDAV service if you want to give it some validatiy. This is a feature not included in Apache 1.3. Now you see why we are using Apache2? We will also want to have authentication enabled so not anyone can commit files to your repository. With all of that completed, save your file and get back to the command prompt. The next step we need to take is adding a user that will be allowed to work with the repository. Key in the following command substituting justin for whatever name you want: sudo htpasswd -c /usr/local/apache/etc/svn-auth-file justin You will be prompted to enter the superuser password and then to create a password for the new user justin. To add more than one user, just run the previous command again, but without the -c flag. It tells htpasswd to create a new file and will overwrite your previously created user. Next, we are going to want to start up Apache and then set up a StartupItem to run Apache each time we restart our Mac. Still in Terminal? sudo /usr/local/apache/bin/apachectl start Assuming you have no errors in typing, your Apache 2 installation should be setup and running. To test it out visit your repository. http://localhost:8800/svn/ You should be prompted to enter a user name and password. Enter one you created before. If it validates, you should see an empty Subversion repository. You are going to want to create a StartupItem to automatically launch, so I have created a StartupItem that you can download here. Place the Subversion folder in /Library/StartupItems/. After that, you are going to want to add the following line to /etc/hostconfig. You can do this in your editor of choice. SVNSERVER=-YES- That's it. Subversion is ready to work from your browser.XCode Integration
Now, it is time to get into the important stuff: Xcode integration. It's so simple.
Open the XCode project file that we checked out in the step before. Once in Xcode, you'll see that your project looks identical to the way it did before. To enable Subversion support, you need to Get Info on your project. In the Project Info window you will see "Enable SCM" at the bottom. Select Subversion from the popup menu. This will enable SCM. Click on the Edit... button and confirm that the Subversion Tool Path is /usr/local/svn
Go ahead and make some changes to some files. Once finished doing that, select SCM from the SCM menu. You will notice that any files that have been modified show up in this window. To commit these changes to the repository, select Commit Changes from the SCM menu. Once committed, the files are removed from the SCM window and you have a new revision.
XCode's Subversion implementation supports the frequently used functions: Update, Diff, Adding new files to the repository, comparing, and getting annotations. Play around with each of those to get an idea of how they function.
That's all there is to it. You now have a local Subversion repository with one project in it that you can access from XCode. While GUI access is great, you should really become acquainted with the inner workings of Subversion. Be sure to check out these resources to get a better understanding. If you have any questions or suggestions, please leave them in the comments.
- Version Control With Subversion - The Book
- http://svnbook.red-bean.com/svnbook/
- cvs2svn - Convert Your CVS Repositories To SVN
- http://cvs2svn.tigris.org/
- The Top 10 Subversion Tips For CVS Users
- http://www.onlamp.com/pub/a/onlamp/2004/08/19/subversiontips.html
- Making The Jump To Subversion
- http://www.macdevcenter.com/pub/a/mac/2004/08/10/subversion.html
Justin Williams is founder and chief author for MacZealots. He switched to the Mac almost five years ago hasn't looked back since. When not blogging or coding, you can find him watching copious amounts of TV. Justin can be reached at



Reader Comments (30)
DISCLAIMER: The views expressed below are those of their authors and not necessarily endorsed or supported by MacZealots.com. In all cases, the comments provided here are offered as a courtesy and will be moderated. Any content deemed off-topic or offensive will be removed without notice. Posting a comment here boils down to two things: 1.) Think before you type 2.) Respect the thoughts of others. See our commenting guidelines and/or privacy policy for more information.
#1) On September 24, 2004 3:09 PM
Subversion is quite nice when used in conjunction with a GUI tool like svnX ( http://www.lachoseinteractive.net/en/community/subversion/svnx ) or scplugin ( http://scplugin.tigris.org/source/browse/scplugin/binaries/ ). You can use Fink (via FinkCommander is my suggestion) to easily install the latest svn and auxillary binaries.
My primary problem with Subversion is the way it handles resource forks. It crushes them. Is there a way to elegantly handle this problem?
#2) On September 24, 2004 3:39 PM
You should also look at http://scplugin.tigris.org/ it adds finder contextual menu support for svn
#3) On September 24, 2004 10:33 PM
I’d like to point out that the most common repository layout (at least, judging from my experience and what The Book says) is to use ‘tags’ rather than ‘releases’.
Steve: I mentioned that to the guys on #svn (irc.freenode.net) and they said they were looking into a solution for resource forks. Hopefully they’ll solve the problem.
#4) On September 25, 2004 2:52 PM
I think releases is a better word than tags. It’s still the same layout regardless of the wording.
#5) On September 26, 2004 12:59 AM
One small gotcha — you cannot successfully visit:
http://localhost:8800/svn/
until you’ve created the /Users/Subversion directory, so the instructions should be reversed.
Also, for us Apache beginners, please be more explicit about setting the port number. I assume we must make the following change to the file /usr/local/apache/conf/httpd.conf:
#Listen 80
Listen 8800
Correct?
Thank you for writing this nice article!
#6) On September 26, 2004 3:52 AM
I have a problem, maybe somebody can help?
In this article, after the short intro to the subversion command line, the author writes
> Now that your repository is created and configured
When did that happen? When I try to open subversion in my browser, I get
Could not open the requested SVN filesystem
I’m not quite sure what I did wrong, so I assumed that I had to create a repository first. I did that using
LKM$ svnadmin create /Users/Subversion
but that didn’t help, still get the same error. And ideas about what I did wrong?
#7) On September 26, 2004 3:55 AM
oh! I just changed the rights so that everyone has write rights to /Users/Subversion. Now it seems to work.
#8) On September 26, 2004 12:36 PM
Hi!
Thank you for the excellent article on Subversion! I’m very excited about getting going. I was following along smoothly until it came time to start apache. This is what I got:
Typed: sudo /usr/local/apache/bin/apachectl start
Received: dyld: /usr/local/apache/bin/httpd can’t open library: /usr/local/apache/lib/libaprutil-0.0.dylib (No such file or directory, errno = 2)
/usr/local/apache/bin/apachectl: line 99: 512 Trace/BPT trap $HTTPD -k $ARGV
Any ideas what I need to overcome this little glich?
Thanks for your help!
Wrashi
#9) On September 26, 2004 1:35 PM
Looks like you forgot to install the APR packages. Grab those from Sanchez’s iDisk, install them, and see what that does.
#10) On September 28, 2004 10:10 AM
Thanks for that! The APR-util_0.9.5-dev-httpd-2.1.dmg package had a .DD2B extention. When I changed it to .dmg it opened and installed properly.
Cheers,
Wrashi
#11) On October 1, 2004 2:38 AM
Any inconsistencies anyone posted here or emailed me about should be fixed now, including the big flub about having you guys launch your invisible repositories.
let me know if you notice anything else.
#12) On October 6, 2004 11:35 AM
Re: Default Permissions
Hi, I’ve been using Subversion for a week now, thanks to this excellent article. This morning I noticed that all of the files I get from a checkout are set with permission 755. Everyone in the world can execute any of these files!?!? Is there any way to change this to something safer without manually changing them?
The other question I have is, how can my Windoze friends checkout something in my repository and add their changes later? I looked through the book posted at http://svnbook.red-bean.com/svnbook-1.0/, and I just didn’t quite understand what the Windoze world needs to do.
Thanks in advance for any help/clarification anyone can give.
Wrashi
#13) On October 10, 2004 8:51 AM
Hello… nice article!
I’m having a bit of a problem, though. I keep getting the following error:
svn: PROPFIND request failed on ‘/svn/Task2_lib’
svn: PROPFIND of ‘/svn/Task2_lib’: 500 Internal Server Error (http://localhost:8800)
Checking the apache error log, I found this:
[Sun Oct 10 05:46:39 2004] [error] [client ::1] (20014)Error string not specified yet: Can’t open file ‘/Users/wlt/Documents/_WLT_Docs/_SVN_/format’: Permission denied
[Sun Oct 10 05:46:39 2004] [error] [client ::1] Could not fetch resource information. [500, #0]
[Sun Oct 10 05:46:39 2004] [error] [client ::1] Could not open the requested SVN filesystem [500, #13]
[Sun Oct 10 05:46:39 2004] [error] [client ::1] Could not open the requested SVN filesystem [500, #13]
Any help is appreciated. Thanks!
#14) On October 14, 2004 12:20 PM
A slight boo-boo in the article:
Calls like this: svn import ~/Development/projectA http://localhost:8800/ [snipped] ..yadda yadda are made to access the Apache2 server, but it’s not configured and started until the Apache Configuration section, which is after those calls. I had to skip around after I realized why that command was complaining.
Also, the configuration file for Apache has Listen instead of Port. This is to second what a previous poster stated.
#15) On October 19, 2004 9:11 PM
Can anybody recommend a bug tracking system that integrates well with subversion?
#16) On November 4, 2004 11:49 AM
You could have a look at Trac (http://projects.edgewall.com/trac/) : “It provides an interface to Subversion, an integrated Wiki and convenient report facilities.”
#17) On November 6, 2004 9:12 PM
Re: bug tracking system
Track Studio (http://www.trackstudio.com/)
It is not the best but if you make commits in svn and put #123 where “123” is a bug/task/etc number, it puts your commit notes into a seperate note record tagged to that task/bug/etc. It tags that note as the “Subversion Subsystem” author so all developers need to initial their commits in the notes section to figure who did what from within track Studio. Otherwise, it requires a trip back to svn to check the log. Other than that, it is basic but lets face it, bugzilla tends to be too much for most.
#18) On November 22, 2004 2:22 PM
Hi, I got the following error message:
Cannot load /Library/Apache2/modules/mod_dav_svn.so into server: dyld: /Library/Apache2/bin/httpd version mismatch for library: /Library/Apache2/lib/libexpat.0.dylib (compatibility version of user: 6.0.0 greater than library’s version: 2.0.0)
I installed everything from wsanchez’ stuff except Apache2 (took the Complete Apache2 package)…
greetz,
Matthias
#19) On November 28, 2004 9:58 AM
Hi there,
Thanks for this very helpful intro. I’ve got two little questions.
(a) I got a bit confused at first: you seem to be importing from “svn import ~/Development/projectA” but have created the projectA directly in your home directory, ie.: “~/projectA/trunk”.
(b) What is the idea behind port 8800. I’ve got an exiting Apache2 running already and happily serving pages on port 80. Is there a reason why I shouldn’t serve /svn on port 80 as well?
Thanks - and also Thanks! again for the article
Martin
#20) On May 5, 2005 3:29 AM
A small comment on the StartupItem (the download) - there is a small inconsistency between the path to “apachectl” fot the start/stop and restart actions - you’ll have to correct that for it to wirk correctly on your system (at that time you can also make sure that the path is the same as what is used on your system…)
#21) On May 8, 2005 2:42 AM
You could mention that XCode support for svn is not as good as it could be. For example renaming file in XCode runs two commands in svn: svn delete && svn add . This destroys the ancestor history (so you cannot tell which file was the original source file of that rename operation) between these two files. The correct way to do renaming and moving of files is to use ‘svn move’ (which has ‘svn rename’ alias as well).
Also adding new files in the project can be problematic. If you add new folder reference to the project XCode don’t usually assign ‘unknown’ SCM status to that folder reference and you cannot add it to repository (so usually you have to use command line svn client to do that). Also, if you add a new folder reference to the project and then commit only changes of files inside that folder (without including folder itself in the commit) a dialog will popup telling you about svn commit error, but the reason of error isn’t displayed (the reason is that you have to include the new folder itself in the commit as well).
#22) On June 6, 2005 12:33 AM
Thanks for this. It worked well, adjusting for the slight hangups listed in the comments. One question I have: I have installed this all on Tiger with XCode 2.0. Within the GUI, when I do a compare, FileMerge opens and lists one difference, bit it doesn’t offer a chance to merge the differences. And when I do a diff a strange “tagged” version of my souce file opens in an XCode window (not File Merge like I would expect). What is the best way to set up svn to do a diff/merge in xCode?
#23) On June 6, 2005 12:35 AM
Thanks for this. It worked well, adjusting for the slight hangups listed in the comments. One question I have: I have installed this all on Tiger with XCode 2.0. Within the GUI, when I do a compare, FileMerge opens and lists one difference, bit it doesn’t offer a chance to merge the differences. And when I do a diff a strange “tagged” version of my souce file opens in an XCode window (not File Merge like I would expect). What is the best way to set up svn to do a diff/merge in xCode?
#24) On July 24, 2005 9:49 AM
Thanks for the great tutorial. I had problems getting this going in XCode 2.1. I believe the main issue was that XCode couldn’t understand the port in the url. I changed the port of Apache to 80, reimported without specify a port, and everything worked perfectly. Another option that I considered was setting Subversion to work over ssh but I couldn’t find the svn+ssh binary.
#25) On July 30, 2005 6:06 PM
Just followed these guidelines - but I used DarwinPorts, which made some of the paths different. I posted the steps I took on my site. I’m getting the same errors as Mathew Crandall, though - says it couldn’t reach localhost:8800 I’ll try setting the port to 80 and see what happens.
Thanks for the excellent tutorial!
#26) On August 8, 2005 2:35 PM
I switched Apache to run on port 80 and everything is working with Xcode now. However, Xcode’s SCM smartgroup only shows code files though (.h and .m). If I make a change to the nib, the data model, or the project preferences, it doesn’t show them as needing updating - I have to use the command line or svnX for that. That does’nt seem right. Is that a setting? Is that just how Xcode works?
#27) On November 10, 2005 5:54 PM
It’s too bad that there does not exist a single Subversion client that comes close to the outstanding TortoiseSVN. SCPlugin has more problems than my inbred stepchild. as of 2004, there have been zero updates or fixes. I have been scouring the net for over a year to find a good Mac SVN client that integrates seamlessly into different types of workflows( Designers, Programmers, Managers etc.) and the only one that has come close is SCPlugin, unfortunately it sucks. Most of the time when Mac users need to do anything of sophistication with Subversion, i refer them to TortoiseSVN (there is no way that I am gonna make a designer use the command line by themselves).
I tried on multiple occassions to contact the SCPlugin developer, but have received no response. The code is basically built using Mac’s plugin architecture (a bastardized version of COM/ActiveX), and there is little to no documentation.
#28) On January 3, 2006 3:27 AM
Awful !
I didn’t understand anything
And do I have to do ALL OF THIS each time I create a new project ? That seems very painful to me, I create a lot of projects and don’t want to have to spend 2 hours just to create the project.
I’m confused by this article…
#29) On February 22, 2006 3:58 PM
I am completely stumped on how you got Xcode to work with Subversion using http authentication. I’m using Xcode 2.2, but it doesn’t prompt me for any authentication information. Instead, the SCM log just shows multiple failed attempts. I’ve even modified the url in the .svn/entries files to include my username and password, but Xcode still has trouble.
Any ideas?
Here’s a sample log error (modified):
cd /Users/mmdd/Projects/iNotify/iNotify.xcodeproj/
/usr/local/bin/svn log http://http_user:http_password@hostname:8888/svn/iNotify/trunk/iNotify.xcodeproj/project.pbxproj
Authentication realm: SVN
Password for ‘mmdd’:
Authentication realm: SVN
Username: subversion/libsvn_ra_dav/util.c:780: (apr_err=170001)
svn: PROPFIND request failed on ‘/svn/iNotify/trunk/iNotify.xcodeproj/project.pbxproj’
subversion/libsvn_ra_dav/util.c:295: (apr_err=170001)
svn: PROPFIND of ‘/svn/iNotify/trunk/iNotify.xcodeproj/project.pbxproj’: authorization failed (http://hostname:8888)
#30) On March 15, 2006 9:40 AM
Eric, if you have that sort of attitude you are obviously not going to become a developer.