Random Ranting (147) · Gadgets & Tech (14) · Anime & Otaku (11) · Watches & Horology (42) · Movies & TV (6) · Photography (3)


Ads

Latest Posts Recent Comments Comrades


My blog is worth $4,516.32.
How much is your blog worth?


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

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 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:

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, “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 (SVN Installation.zip) available here.

Mount the disk images and install all of the packages. If you are remotely connected to the server, you can use hdiutil to mount each disk image and use installer to install the package from each volume mounted by the disk images.

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

In this example note that the installer command and all arguments must be entered on the same line; the \ is used to indicate line continuation:

% 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 ‘$ 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:

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, “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 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):

[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,

[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 /usr/local/apache/conf/httpd.conf. Add the command to load the WebDAV/Subversion module at the end of the LoadModule commands (around line 118) as follows:

# 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):

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the 
# 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.

<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
</Location>

The svn-authz-file is edited as follows,

[/]
mike = rw
* = r

This gives read-only access to ‘/’ (which is /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 /usr/local/apache/etc/svn-auth-file. To CREATE this file enter the following command (you will be prompted for a password):

$ sudo htpasswd -cm /usr/local/apache/etc/svn-auth-file 

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

$ sudo htpasswd -m /usr/local/apache/etc/svn-auth-file 

Now start up Apache2 by issuing the command:

$ 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 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 /Library/StartupItems/Subversion. Ensure that the Subversion directory belongs to root:wheel by performing,

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

After that, you are going to want to add the following line to /etc/hostconfig. You can do this in your editor of choice, such as vi or emacs

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.

  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 svn import command and all arguments must be entered on the same line, the \ is used to indicate line continuation.)

[16:39:09] localhost:~ mike$ svn import -m “initial import” \
~/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,

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

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

[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,

$ 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,

$ 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 ~/codedump/. We are now going to import this into our SVN repository as follows,

[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,

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

Now, open up ~/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 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 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

25 Comments »

  1. bsodmike.com » Using Subversion (SVN) in OS X with XCode & Apache2 said,

    November 6, 2006 @ 19:40

    [...] I finally managed to finish this article today, mainly as I was setting up SVN for work. Simply making multiple copies of source-code was getting tedious and hard to track. Check out the full article here. [...]

  2. Firestarta said,

    November 7, 2006 @ 1:55

    Hmm, comments.. comments. All I have to say to you is NOODLES!

  3. bsodmike said,

    November 7, 2006 @ 1:57

    testing page comments

  4. bsodmike (as guest) said,

    November 7, 2006 @ 2:05

    Weeeeeeeeeeeeeeee!

  5. bsodmike.com » Using Subversion (SVN) in OS X with XCode & Apache2 said,

    November 13, 2006 @ 21:23

    [...] It walks you though the stages of setting up SVN, Apache2 and finally how to Integrate SVN access into XCode projects!read more | digg story [...]

  6. Steve said,

    November 15, 2006 @ 8:12

    Hi,
    I’m trying to install the subversion apache server. The instructions here point me to Fred Sanchez’ public iDisk, but that requires a password that I don’t have. You also provide a zip file, but I can’t seem to unzip it. And fink gives me an error when I try to install svn. I’m guessing that I’ve completely misunderstood your directions. Any suggestions?

    Thanks,
    Steve

  7. bsodmike said,

    November 15, 2006 @ 8:22

    Hi Steve,

    I actually never had any luck in uploading the zip - I have a crippled form of ADSL @ home with 128kbps upload which stalls alot :/

    Connect to fred’s iDisk and keep clicking cancel. If it doesn’t stop, enter the username ‘wsanchez’ perform a combination of ok/cancel - it worked for me. Then grab the files you need. Finks error, that’s not a problem as fink (if it did install at all) would put it somwhere in /sw/bin, whereas this method puts it /usr/local/subversion/bin

    You’d want to make sure that there isn’t any clashing between whatever you did with fink and this as well. A problem will arise if you have svn setup in two places, so it would be best to uninstall svn if fink succeeded but from the sound of things, I don’t think you got that far. I’m stating this for your info as well as others. Also remember to update the $PATH in your .bash_profile (I’ve mentioned what needs to be done twice).

    Let me know how it goes. Just to make something clear, I didn’t use fink at all in setting this up, but I’m sure there are ways of getting it working with fink - but I found this method fast and painless and I have a stable SVN server running on my pbook accessible by all my Macs @ Home :)

    Cheers,
    Mike

  8. bsodmike said,

    November 15, 2006 @ 8:32

    As for the iDisk, I had to click cancel 4 times and it let me access it.

  9. bsodmike said,

    November 17, 2006 @ 11:36

    Another note. Since I have got the SVN/WebDAV server running on my pbook, on all my ‘client’ machines I tend to simply install Martin Ott’s set of SVN tools, which installs svn in /usr/local/bin.

    After checking out whatever project I wish to work on, firing up XCode and enabling ‘SCM’ is a simple matter - giving me full SVN access ;)

  10. Don Carlile said,

    November 24, 2006 @ 12:14

    Good job! I’m not completely set up yet (I need to import projects), but this was very helpful in getting me to where I am.

    One correection for you. In the code to add to the end of the httpd.conf file, you omitted the

    at the beginning and the

    at the end of the block.

  11. Don Carlile said,

    November 24, 2006 @ 12:16

    oops! It masked out the Location tags in my comment. Let me try this:

  12. Don Carlile said,

    November 24, 2006 @ 12:17

    OK, at the beginning
    angle bracket Location /svn angle bracket
    angle bracket /Location angle bracket

  13. Michael Rogers said,

    November 29, 2006 @ 1:05

    I liked the article a lot, thanks for writing it. The only things I found that in the line about htpasswd, you need to specify a user, and on my Mac the line for LoadModule is 118, rather than 181.

    Unfortunately, I never actually got apache to run. I get an error message:

    Bad address: Could not set permissions on ssl_mutex; check User and Group directives
    Configuration Failed

    Any ideas?

    Thanks,

    Michael Rogers

  14. bsodmike said,

    December 6, 2006 @ 15:25

    Don: Thanks, I’ve fixed that - it was being parsed as XHTML, go figure. Used an HTML ‘escape’ sequence to fool it.

    Michael: Cheers, I’ve marked the correct line number in the article. This Apache error, is it once you to attempt to launch it? Please go back through the steps specially htpasswd and other ‘access’ settings - seems like somethings missing.

    Also double check that you’ve edited the httpd.conf correctly, to include the appropriate settings and additional modules.

    I’m glad this article has helped - expect more like this in the future. Your feedback is greatly appreciated as well :)

  15. Steven Noyes said,

    December 12, 2006 @ 6:42

    Just a note. After following these instructions, things worked like a champ EXCEPT locking. It turns out you need to change the group-ship of the Repository to match the root user. On some systems, this seems to be admin and on other it is wheel. If they do not match the groups the error:

    Failure when attempting to lock a file: Can’t chmod

    may be seen

  16. bsodmike said,

    December 16, 2006 @ 18:17

    Ah, thanks for the tip!

  17. Michael de Silva said,

    December 28, 2006 @ 14:11

    This is a follow up reply to the post by Michael Rogers,

    Bad address: Could not set permissions on ssl_mutex; check User and Group directives
    Configuration Failed

    I’m getting this with my new MBP, and seems like an issue restricted to MBPs as I do not think the files installed are Universal Binaries (?). The best way to go would be to install everything by hand via fink.

  18. bsodmike.com » TGIF… said,

    February 10, 2007 @ 17:28

    [...] Yesterday the 1.6GHz G5 was returned after the power supply was replaced and since then has been setup as a remote (headless) 24/7 SVN server. I am currently in the process of setting up a backup system, which might include a mix between a gcc program and/or a shell script since my pb, which hosted the previous repository, died. However, I was able to have the Apple tech’s extract the HDD the very next day and I was able to copy the repository and backup the rest of the files. After configuring what I now call ‘SVNG5′ I simply just ‘copied’ the repository I copied off the powerbook - it loaded up to revision 13 right away. [...]

  19. pingu said,

    February 15, 2007 @ 19:41

    Nice!

  20. Jessie said,

    February 27, 2007 @ 18:26

    Could we do it with virtualhost.sh as well?

  21. Owen Mathews said,

    March 26, 2007 @ 18:59

    By the way, you don’t have to use port 80 to get it to work with XCode. I left mine on 8008 and XCode talked to it flawlessly.

  22. Juancho said,

    September 13, 2007 @ 5:35

    I have a problem when I install the subversion package…After I export the PATH to the profile and then I type svn -version, the output is:

    dyld: Library not loaded: /usr/local/apache/lib/libaprutil-1.0.dylib
    Referenced from: /usr/local/subversion/bin/svn
    Reason: image not found
    Trace/BPT trap

    If somebody has the solution, let me know…

    Thanks..

  23. Mark said,

    September 19, 2007 @ 22:17

    >dyld: Library not loaded: /usr/local/apache/lib/libaprutil-1.0.dylib
    >Referenced from: /usr/local/subversion/bin/svn
    >Reason: image not found
    >Trace/BPT trap

    I had a similar problem. I found that my libapr files were all bad links in /sw/lib

    Trying doing ‘ls -al /sw/lib/*apr* to see whether things are lined up right.

  24. Dude said,

    January 24, 2008 @ 18:00

    I was wondering if anyone has good references on how to manage the branches thing.
    Cheers
    Dude

  25. Georgio Layout said,

    August 27, 2008 @ 9:44

    I have XCode 2.4.1 and i svn is configured according to the suggested steps but my problem is with XCode!

    I get the following SCM error when i try to commit the entire project:
    svn: Commit failed (details follow):

    with no details at all!!!!
    what is going wrong??

RSS feed for comments on this post · TrackBack URI

Leave a Comment


Google Search


RSS/Meta Articles