Subversion Tips

Source control is an important concept in modern day programming, especially when working in a team environment. Most Microsoft-based shops use either Sourcesafe or Team Foundation Server (TFS). TFS is a great product, it does everything under the sun, but at a pretty hefty cost. In steps Subversion, lightweight, capable, and (drum roll)… free! I tend to promote things that are both competent and well priced. I certainly encourage you to look into Subversion as an alternative to TFS if you lack the size or resources at your current stage of development.

Below, I’ve outlined a few pieces of information that I found useful while setting up Subversion and integrating it into my Visual Studio instance. This is by no means comprehensive, as you can find much more information and specific instructions for installation and use from Subversion directly. Consider this the “cliff-notes” version.

The Tools You Need

CollabNet Subversion

CollabNet Subversion

CollabNet provides an “enterprise-ready distribution of Subversion”. It is simply another flavor of Subversion which is purported to be one of the most stable versions. This provides the server and command-line client.

Tortoise SVN

Tortoise SVN

Tortoise SVN provides a graphical interface for using Subversion as a shell extension. You simply install Tortoise SVN, right click on a folder and are provided with additional Subversion actions within the file context menu. Additionally, you can use the Repo-Browser to open a File Explorer-like view of the source controlled files.

Ankh SVN

Ankh SVN

Ankh SVN is a Visual Studio plugin which can be added to integrate Subversion into Visual Studio (similar to TFS/Sourcesafe).

There are several tools available that you can use in place of these, but I’ve found these three work pretty smoothly for real-world use.

Setting up a Repository

Creating a repository once you have Tortoise SVN installed is very easy. Create a folder in Windows, for example, c:\svn; right click on the folder, in the context menu, inside TortoiseSVN, select “Create repository here”. See screenshot below.

This will automatically setup all of the directories and files necessary for a repository where you can begin adding source controlled files and projects to.

Create SVN Repository

Making the Repository Available Online

To allow your Subversion repository to be available remotely, you’ll need to add it as a service on a hosting server. You can do this by running the following command (change directory paths to match the location of subversion as well as the location of the repository) on your server.

sc create svn binpath= "\"c:\program files\collabnet subversion server\bin\svnserve.exe\"
--service -rc:\svn" displayname= "Subversion Server"
depend= Tcpip start= auto

Kick off the service if it is not already running, by entering the following command line:

sc start svn

Setting up Access/Authorization

Once you create a repository, open the folder (c:\svn), and open the “conf” folder to see the following files:

  • authz
  • passwd
  • svnserve.conf

authz File

The authz file contains a sample “database” of authorization rules which can be used by Subversion to limit access to users, groups, or aliases. Let’s take an example of two users, Bob and Susan. First we need to add the users to the [users] section and assign them read/write (rw) access, as follows:

[users]
bob = rw
susan = rw

Next, we’ll need to modify the authz file to specify that all authenticated users have access to the repository; we do this with the following:

[users]
bob = rw
susan = rw

[/]
$authenticated = rw

There are several additional examples and notes autogenerated within the authz file; you can learn quite a bit by playing around with these entries.

Limiting Access to Specific Directories

Let’s now further restrict the repository so specific users will have access to certain areas, while others will not. Bob will have full access to the entire repository, while Susan will have access to everything except a directory called “private”.

Our repository directory will look like this:

c:\svn
c:\svn\private
c:\svn\public

In the authz file, we need to make an additional change to designate that only Bob has access to the private directory. Here is our previous authz file with the new access rule; we’ve added the directory to which only Bob has access to. The two criteria beneath the rule indicate to set access of ” (none) to everyone (*) which essentially blocks read/write access from all users. We then add to that entry by saying Bob = rw (read/write access for Bob only) in the next line to allow Bob access.

[users]
bob = rw
susan = rw

[/]
$authenticated = rw

[/private]
* =
bob = rw

passwd

The passwd file contains a “database” of users and corresponding passwords. Simply add your authenticated users and their passwords (one per line):

[users]
bob = password1
susan = password2

svnserve.conf

The svnserve.conf file contains several configuration settings for Subversion which you will need to modify to enable access control.

Here are the key entries that you should adjust:

anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = My Repository

There are directions and examples in the svnserve.conf file that are generated when you create a repository. The above example is pretty standard if you are going to allow multiple authenticated users to access your repository while keeping anonymous users out.

Further Information

You can find an abundance of documentation in the above links as well as at http://subversion.tigris.org/. If you have any quick tips that you would like to share, please add them below in the comments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s