Monday 24 November 2008

Setting up source control

I have from time to time had to set up source control on a new system, or after formatting a system that's grown old over time. The steps are pretty simple if you follow the instructions, but they can ramble on a bit in my opinion. I want something short and quick to follow, so when I decided to put source control on a new development box I decided to post this as much for myself as for anyone else.

Steps to setting up Subversion source control

The steps below describe how to set up source control for local use and do not require installation of an Apache web server to allow remote access.

  1. Download and install SVN
  2. I chose Slik Subversion. The same page has links to AnkhSVN (see below). Installation was smooth but for the registration of the service (didn't happen, and no error message). The command line to register my installation of the service was:

    sc create Subversion binpath= "C:\Program Files\SlikSvn\bin\svnserve.exe --service --root D:\Repository.SVN" displayname= "Subversion" depend= Tcpip start= auto

    I ran into the following error because by default on Vista, all things run as normal user.

    [SC] OpenSCManager FAILED 5: Access is denied.

    Screenshot showing how to set a command prompt to run with admin rightsThe solution is pretty simple; you make the command line run as administrator as follows: Edit the properties of the command line link and on the [Shortcut] tab, press the [Advanced...] button and then tick the [Run as administrator] option. Press OK twice to close the properties and then run the command line. You might be prompted to continue with administrator rights.

  3. Download and Install AnkhSVN
  4. If you want Visual Studio integration (and who would not want this?) you need a client tool such as AnkhSVN.

    Installation was simple, and it registered with both VS2005 and VS2008 on my system. The new version has icons that show the checked out/in status of each file under source control. It also has very good integration with the pending changes and a neat history viewer.

  5. Install TortoiseSVN
  6. This shell extension will highlight which files and folders are under source control by embellishing their icons with indicators. Tortoise also has a useful repository browser which can be loaded from an explorer context menu when no file is selected.

  7. Backup
  8. No installation of source control is complete if you aren't backing up that repository. Schedule a task to run as frequently as you desire. I used the svnadmin program to make a hotcopy of the repository/ies I have. Using the same example repositoryy as above, the backup is done with one simple command:

    svnadmin hotcopy D:\Repository.svn c:\backup\D_Repository.svn

    New entry 14 June 2009: I've just written a batch file to perform the backup and compress the backed up repository to a ZIP file with the current date. I know I'll need this again, so I'm posting it here. The two things to care for are highlighted in yellow.

    @echo off
    set backupDT=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
    set backupFolder=Backup_Repository_%backupDT%.svn
    echo Removing existing backup folder
    rd %backupFolder% /S /Q
    echo Backing up repository to %backupFolder%
    svnadmin hotcopy C:\repository\Svn %backupFolder%
    set backupZipFilename=SvnBackup_%backupDT%.zip
    echo Compressing repository into %backupZipFilename%
    D:\UTIL\zip -r -9 -S -o %backupZipFilename% %backupFolder% > nul
    echo Removing backup folder (contents are in ZIP)
    rd %backupFolder% /S /Q
    pause

No comments:

Post a Comment