bsodmike's photostream @ www.flickr.com

HOWTO: Using Subversion (SVN) in OS X with XCode & Apache2

27/01/2010


IMPORTANT: XCode v2.4 is incompatible with SVN v1.40 – Please download XCode version v2.4.1 from the ADC website, which corrects this problem and has been tested for compatibility.

This article has been created from my own experience in setting up SVN for work using the references listed below and this article may contain portions of text from these sources. Credit is due to all concerned and I do not claim full ownership of this article.

The files were downloaded and configured on an Apple 1.67GHz PowerPC G4 PowerBook running Mac OS X v10.4.8 (Build 8L127) with 1.5GB DDR2 SDRAM.

If you have any suggestions and/or would like to contribute to this page, please use the menu to contact me.

Subversion: Client-side Installation

Most users will only need to install the Subversion client-side tools. Download the statically linked package from Martin Ott’s site. Download the latest version of the Subversion client (currently Subversion-1.4.0.pkg.zip).

Only download Martin Ott’s

1
Subversion-1.4.0.pkg.zip

if you are *not* performing the server-side installation or alternatively, see the server-side installation notes below for instructions on how to install the individual packages (the client installation only requires these packages: APR, APR-util, Expat, Subversion).

For convenience, add the path to your executable search path. For the bash login shell, add the following lines to your ~/.bash_profile file:

1
2
PATH="/usr/local/bin:/usr/local/subversion/bin:$PATH"  
export PATH

To verify your installation, enter ’svn’ into a terminal window. The command should respond with the message, ”

1
Type 'svn help' for usage.

“.

Subversion: Server-side Installation

To set up a network accessible repository, you’ll need to install a few packages on the computer you choose to use as the repository server. Once the packages are installed, then the actual repository must be created and configured for access from client users over the network.

Download and install these individual packages. The packages are available for download as disk images from Fred Sanchez’s public iDisk or as a zip file (

1
SVN Installation.zip

) available here.

  • Apache-HTTPD-2.2.3.dmg
  • APR-1.2.7.dmg
  • APR-util-1.2.7.dmg
  • Expat-2.0.0.dmg
  • Libxml-2.6.26.dmg
  • Neon-0.25.5.dmg
  • Subversion-1.4.0.dmg
  • SWIG-1.3.29.dmg

Mount the disk images and install all of the packages. If you are remotely connected to the server, you can use

1
hdiutil

to mount each disk image and use

1
installer

to install the package from each volume mounted by the disk images.

1
2
% hdiutil attach <disk_image_file>
% installer -pkg <package_file> -target <target_volume>

In this example note that the

1
installer

command and all arguments must be entered on the same line; the \ is used to indicate line continuation:

1
2
3
% hdiutil attach ~/Desktop/Subversion_1.0.5.dmg
% installer -pkg /Volumes/Subversion_1.0.5/Subversion_1.0.5.pkg \
-target /

Each package will be installed into /usr/local/<package_name>.

As an alternative you may install these packages via fink. A simple ‘

1
$ sudo fink install svn

‘ should do the trick.

For convenience, add the path to your executable search path. For the bash login shell, add the following lines to your ~/.bash_profile file:

1
2
PATH="/usr/local/bin:/usr/local/subversion/bin:$PATH"  
export PATH

To verify your installation of Subversion, enter ’svn’ into a terminal window. The command should respond with the message, ”

1
Type 'svn help' for usage.

“.

Now you have all of the necessary packages installed on the server. The only remaining steps are to create the repository and set up client access.

Because you are using Apache to provide access to the repository, you’ll need to create HTTP/Apache user accounts to determine repository access restrictions and ownership of file revisions in the repository. These are accounts used within the repository and are completely independent of the Unix/login accounts configured on the server. These accounts are set up as HTTP/Apache users.

Outside of the repository, you need an account that owns the repository database and supporting files. Apache2 will need to have read/write access to files owned by this account.

In reality, this is easy to deal with. Make the Mac OS X standard web server account, daemon, the owner of repository files and also the account that the Apache2 process runs as. Then create an HTTP/Apache authentication file using

1
htpasswd

to set up the users for the repository.

For the purpose of this article, and even on my work machine, the repository is located at /Users/Subversion

Enough talk, time for action! Create the repository on the server using the following command (perform the following commands as root or authenticated via sudo):

1
2
3
4
5
[16:38:14] locahost:~ mike$ sudo svnadmin create /Users/Subversion
[16:38:40] locahost:~ mike$ ls -la /Users/
drwxrwxr-t   10 root     admin         340 Nov  6 16:38 .
drwxrwxr-t   34 root     admin        1258 Nov  2 21:42 ..
drwxr-xr-x    9 root     admin         306 Nov  6 16:38 Subversion

By default Apache 2 operates under the user daemon, so we give ownership of the directory as follows,

1
2
3
4
5
[16:38:43] locahost:~ mike$ sudo chown -R daemon /Users/Subversion/
[16:39:06] locahost:~ mike$ ls -la /Users/
drwxrwxr-t   10 root     admin         340 Nov  6 16:38 .
drwxrwxr-t   34 root     admin        1258 Nov  2 21:42 ..
drwxr-xr-x    9 daemon   admin         306 Nov  6 16:38 Subversion

Apache2 Configuration

Before starting the Apache2 daemon, it needs to be configured. Configure Apache2 to access the repository by editing

1
/usr/local/apache/conf/httpd.conf

. Add the command to load the WebDAV/Subversion module at the end of the

1
LoadModule

commands (around line 118) as follows:

1
2
3
# For SVN
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

To avoid conflict with the standard OS X Apache configuration, set a different port to listen for http requests. Replace the existing line configuring “Listen (port)” with the following (for the rest of this article we’ll assume use of port 8008):

1
2
3
4
5
6
7
8
9
10
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 8008

Add the following text to the end of the configuration file to let Apache2 know the path to the repository and the HTTP/Apache user accounts file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
&#60;Location /svn>
  DAV svn
  SVNPath /Users/Subversion
 
  # our access control policy
  AuthzSVNAccessFile /usr/local/apache/etc/svn-authz-file
 
  # only authed users may access the repository
  Require valid-user
 
  # how to authenticate a user
  AuthType Basic
  AuthName "Subversion Repository"
  AuthUserFile /usr/local/apache/etc/svn-auth-file
&#60;/Location>

The svn-authz-file is edited as follows,

1
2
3
[/]
mike = rw
* = r

This gives read-only access to ‘/’ (which is

1
/Users/Subversion/

) to all users and read/write access to myself. Substitute ‘mike’ with your Apache2 user name.

The svn-auth-file contains a list of Apache2 users and their associated password, which is not associated with Unix/login in any manner. Now, configure HTTP/Apache accounts. I put the authentication file in

1
/usr/local/apache/etc/svn-auth-file

. To CREATE this file enter the following command (you will be prompted for a password):

1
$ sudo htpasswd -cm /usr/local/apache/etc/svn-auth-file <username>

Note, to add users to an existing file, skip the -c option:

1
$ sudo htpasswd -m /usr/local/apache/etc/svn-auth-file <username>

Now start up Apache2 by issuing the command:

1
$ sudo /usr/local/apache/bin/apachectl start

You’re now done with the setup and installation! To verify that the server installation was successful enter the URL specified for the location of the repository (as configured in the

1
httpd.conf

file) into Safari, and in our case http://localhost:8008/svn will take you there. You should be prompted for a username/password combination and upon successful authentication see a revision number and the contents of the top directory of your repository (it should be empty).

svn

svn

svn

To be able to access the SVN WebDAV repository at every reboot, we require a StartupItem to load the Apache2 daemon. This can be enabled by downloading and installing a StartupItem, located here. Extract the contents of the compressed archived into

1
/Library/StartupItems/Subversion

. Ensure that the

1
Subversion

directory belongs to root:wheel by performing,

1
$ sudo chown -R root:wheel /Library/StartupItems/Subversion/

After that, you are going to want to add the following line to

1
/etc/hostconfig

. You can do this in your editor of choice, such as

1
vi

or

1
emacs
1
SVNSERVER=-YES-

That’s it. Subversion is ready to work from your browser.

Using Subversion

These suggestions on using Subversion are taken from the book Version Control with Subversion. This is a simplified view of using Subversion, and I’ve included page/section references where the Subversion book addresses an issue more completely.

1. Choosing a repository layout scheme.
Before adding projects to the repository, it’s worth choosing how you’d like to organize the repository layout. On the other hand, thanks to the ease of moving and renaming directories in Subversion, it’s easy to rearrange things later. I’ll recommend one simple layout taken directly from the Subversion book (see page 81: Choosing a Repository Layout).

This layout is based around tracking three aspects of each project:

  1. Trunk — the ‘main line’ where active development is managed.
  2. Branches — where a copy of the project can be managed without affecting the main line – useful for testing out big changes that may or may not be later integrated into the main line (see page 39: Branching and Merging).
  3. Releases (or tags) — where snapshots (usually corresponding to an official release of the project) of the source tree are kept so that it can be restored, examined and rebuilt if needed (see page 51: Tags).

The following example demonstrates how this layout would work for two projects, ProjectA and ProjectB.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  ProjectA/
     trunk/
        ... project files ...
     branches/
        CustomClientBuild
           ... project files ...
     releases/
    v0.9b/
           ... project files ...
        v1.0/
           ... project files ...
  ProjectB/
     trunk/
        ... project files ...
     branches/
        ... project files ...
     releases/
        ... project files ...

2. Importing a project into the repository.
So this is the big event — actually taking one of your projects and adding it to the repository. Using the repository layout described above, here’s how you would add ProjectWidget to the repository. (Note, the

1
svn import

command and all arguments must be entered on the same line, the \ is used to indicate line continuation.)

1
2
3
4
5
6
7
8
[16:39:09] localhost:~ mike$ svn import -m "initial import" &#92;
~/sim http://localhost:8008/svn/sim/
Adding         ~/sim/releases
Adding         ~/sim/trunk
Adding         ~/sim/trunk/main.c
Adding         ~/sim/branches

Committed revision 1.

If the file main.c is altered, we can check this by performing,

1
2
[19:05:00] localhost:~ mike$ svn status
M      main.c

We can now commit the changes, thus updating the repository,

1
2
3
4
[19:05:04] localhost:~ mike$ svn commit -m "added two blank lines"
Sending        trunk/main.c
Transmitting file data .
Committed revision 2.

This example of accessing our SVN repository, editing a file and committing the changes is quite basic, and can get tedious from the command line. You can now continue to install snvX, but remember to update the location of SVN in svnX as follows,

svnX

XCode Integration

Since setting this up is unclear, we are now going to take a few steps back.

XCode expects the SVN WebDAV server to connect on port 80, therefore the Apache2 daemon needs to be stopped,

1
$ sudo /usr/local/apache/bin/apachectl stop

…edit the httpd.conf to connect on port 80. Before starting the Apache2 daemon, now load up the system preferences pane and ensure that OS X’s default Apache is not running. Now continue to start the daemon like before,

1
$ sudo /usr/local/apache/bin/apachectl start

Getting projects to work with XCode is a little tricky but this is what must be done. Open up XCode and create your project, and for arguments sake it will be located in

1
~/codedump/

. We are now going to import this into our SVN repository as follows,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[04:32:12] localhost:~ mike$ svn import -m "initial import" ~/codedump/ http://localhost/svn/codedump
Adding         ~/codedump/releases
Adding         ~/codedump/trunk
Adding         ~/codedump/trunk/build
Adding         ~/codedump/trunk/build/codedump.build
Adding         ~/codedump/trunk/build/codedump.build/...
..
..
Adding         ~/codedump/trunk/codedump.1
Adding         ~/codedump/trunk/main.c
Adding         ~/codedump/trunk/codedump.xcodeproj
Adding         ~/codedump/trunk/codedump.xcodeproj/michaeldesilva.pbxuser
Adding         ~/codedump/trunk/codedump.xcodeproj/project.pbxproj
Adding         ~/codedump/trunk/codedump.xcodeproj/michaeldesilva.mode1
Adding         ~/codedump/branches

Committed revision 1.

…and we check it out to a folder in the home directory, where I will perform all development in,

1
[04:33:00] localhost:~ mike$ svn checkout http://localhost/svn/codedump ~/XProjects/codedump

Now, open up

1
~/XProjects/codedump

and launch the project file, which will open up the project in XCode.

Highlight the project and click on the big blue ‘i’ located at the top right, for info,

XCode & SVN

The following pane should pop up,

XCode & SVN

Choose ‘Subversion’ at the bottom, and click ‘Edit..’, and update the toolpath,

XCode & SVN

…and tick ‘Enable SCM’. This will cause the connection to the WebDAV SVN repository.

Now edit the file

1
main.c

and it should appear with a ‘M’ as shown below, which means ‘modified’,

XCode & SVN

Click on the ‘SCM’ menu and choose ‘Commit changes’ and after you add a message for the commit, if you look under SCM info while having

1
main.c

selected in the project view,

XCode & SVN

…and here’s what it looks like when you perform a ‘version’ compare,

XCode & SVN

References

Last Updated on 07.11.2006

No Comments

About

For the past couple years I lived in the UK, reading in BEng (Hons) Electronic and Computer Engineering at The University of Leeds and MSc (Dist) Mechatronics at King's College London.

My interests and hobbies include writing with Fountain Pens on various ink and paper, Swiss and German wristwatches, authoring articles in Mathematics, Physics, and Engineering, and Gundam modeling.

I have been following much Anime over the years as well as TV Shows with the likes of 24, Smallville, Dexter, and NCIS becoming favourites.