For those of you who don't know, Subversion is a version control system. Basically it enables you to track all changes to a project. It gives added security and control to the integrity of your work enabling you to compare a document with any previously saved version, and revert to, or merge different versions of a document.
In this tutorial I will show you how to set up Subversion to work with Coda on the Mac. Coda from Panic Inc. is my app of choice when it come comes to web development on the Mac — it may not do everything, but it does a lot and it makes working with Subversion a cinch!
For the purposes of this tutorial I will assume that you develop sites locally, as I do, using MAMP and will be installing Subversion locally to manage your projects as you work on them.
1. First you need to get yourself a copy of Subversion. Go to http://www.open.collab.net/downloads/community/ and download the latest binaries, then install. (the installer will install Subversion to: /opt/subversion/bin/svn ).
2. The next thing you need to do is create a repository. The repository is where all of your versioned data will be stored. You can locate it anywhere you like, personally I have mine in my home directory, where I also have the directory that is the root level of my localhost server. To create the repository, you need to access the command line. Open a terminal window and navigate to your chosen location (in my case: cd /Users/duncan/) and then create the repository: svnadmin create SVNrep - this will create a repository in the home folder called SVNrep.
3. OK, now that SVN is installed and you've created a repo, you need to configure it. In the Finder, open the directory 'conf' that resides inside your repo. (in this case /Users/duncan/SVNrep/conf/). Using a text editor, open the files svnserve.conf and passed. In svnserve, you need to uncomment and amend the following lines:
anon-access = none
auth-access = read
password-db = passwd
realm = My Repo
Save and close this file, then add a line to the passwd file to set your username and password, for example:
myusername = mypassword
Then save and close the passwd file.
4. Now to add your project to the repo - again, this will be done using the command line. Again, I'm assuming that you have many sites on the go, and each is sitting in a separate folder on your server - let's say you have one called 'my_great_site'. To add this to the repo type the following:
svn import my_great_site file:///Users/duncan/SVNrep/my_great_site -m "Initial import"
The path will be different for you depending on where you have put your repo and what you have called it.
5. Now you can delete you site as its safely stored in the repo (OK, you don't want to delete it, just move it out of the root level of your server and archive it somewhere).
6. To work on your site, you need to checkout a 'working copy' from your repository (terminal again!). Type the following:
svn checkout file:///Users/duncan/SVNrep/my_great_site Webserver/my_great_site-SVN
As before you may need to adjust the paths depending on A. where you repository is (in this case: /Users/duncan/SVNrep, and where your server root is: /Users/duncan/Webserver/ ). The final -SVN is not necessary, it's just my way of visually marking the project as being under version control.
7. OK, now the project has been checked out, it's time to update your site settings in Coda. First, open the preferences - Coda > Preferences... and click on the 'Files' tab. Enter /opt/subversion/bin/svn into the 'Subversion Tool Path:' field, then close the preferences.
8. Nearly done, now it's time to update your site settings in Coda. Open the 'Sites' tab and click on the 'i' icon for your site. (pic). If you added -SVN to your checked out copy (or called it something different entirely, you will need to adjust the 'Local URL:' and 'Local Root:' fields). Now scroll down to the bottom, and expand the 'Source Control' section. Check the 'Enabled' checkbox and then enter you username and password that you set up in stage 3. If the Repository URL is not already set, close the sites panel and open it again. If it's still not set you may need to add it manually - in this case it would be: file:///Users/duncan/SVNrep/my_great_site
9. That's it - your site is now under source control, check out the 'Managing Files With Source Control' section of the Coda Help files - enjoy!