Thursday, July 1, 2010

How to get SubVersioN on Mac OS X 10.6?

Even if you work on a project on your own it's worth having version control system in place. It helps to keep things tidy and gives you time machine possibilities for working with your code (I am not talking about the trademarked machine). I like SVN which is mature and seems to have it all. Let's have a look how to install that beast on our lovely Macs.

Download SVN for free

First good news - SVN comes with a nice Mac-like installer and is completely free and published under Apache Licence. You can download it from CollabNet website. It requires free registration which at first seems a bit dodgy but CollabNet is the company responsible for creating SVN and it's a good source.

Install SVN on Mac OS X 10.6

Once you have downloaded the package it's time to install it. The installer looks all pretty and takes no longer than just a few moments. It installs the whole svn bunch (server and client) in /opt/subversion directory. The only downside is that you don't get any fancy application like you do for MAMP to control it. After you've finished the installation it all happens in the command line... but cheer up, it's not that scary. You will get it up and running in no time.

Set up evironment

SVN gives you complete freedom of the location of your repositories. It goes like this. You create a directory wherever you wish and tell your svn server to feel at home in there. That directory is then your svn server root directory. Your SVN server will create your repositories in there.

Let's get started then. Since all the svn related programs are located in /opt/subversion/bin you have to specify the path every time you need to run them. It's not handy at all, we would prefer not to worry about where they are. That's not a biggy. Fire up your Terminal (it's that monitor icon in /Applications/Utilities) and edit the file .profile in your home directory. I, for one, like vim but it might be slightly depressing experience at first if you are not familiar with it. In that case use pico, it's really straighforward

$ pico .profile
and add the following line at the end of the file:
export PATH=/opt/subversion/bin:$PATH
The .profile file is read every time you create new shell, so next time you open your Terminal the change will be applied. Because we don't want to close the Terminal just yet only to reopen it let's cheat a tiny bit:
$ . .profile

Well done! Let's check if it works

$ svn
Type 'svn help' for usage.
If you got similar output you are ready to proceed.

Set up SVN repository

Now it's time to create root directory for the SVN server. You can name it whatever you like and create it even in your home directory if you wish. SVN is not fussy at all. Let's do that then and let's give it meaningful name "svnrepos".

$ mkdir svnrepos
And finally it's time to launch your SVN server. By the way it's not a typo, there is no 'r' at the end:
$ svnserve -d -r svnrepos
There are no repositories. All we have is just SVN server ready for action. Let's give him something to look after. If you want to create a test repository to play with it for a while, just do this:
$ svnadmin create svnrepos/test

Set up privileges

Congratulations! You have just created your repository. Good thing is you don't need to worry about having to do some magic tricks later on to get rid of the test repository whenever you feel like it. Simply delete the directory svnrepost/test and it's gone forever. For now though, it's accesible through the URL svn://localhost/test but you cannot do much with it unless you grant yourself the privileges.

SVN server keeps access control lists per repository, so you need to dive into config directory of your newly created repository and conquer! Sounds like a big job but it isn't. All it takes is adding one line in one file and removing one comment in another one. Go to svnserve/test/conf and edit the file passwd first. Here you will add your preferred username and password. It's easier when you choose your Mac username. For example, my Mac username is "jacek" and my password for the test repository is "test", so I added a line jacek = test.

Next edit the file svnserve.conf and remove comment from the line saying password-db = passwd.

Believe it or not, that's it! Now you can access your repository through your favourite SVN client and do whater SVN clients do. One thing you need to remember is to run

svnserve -d -r svnrepos
every time you start your Mac. Of course it's quite easy to make it happen automagically but that's for another story.

Thanks for reading. I hope you found this guide useful, it worked for you and made you a bit happier. Please don't think twice before you leave your comment.

Jacek