We have seen a good list of configuration management tools in the previous post “Top Open Source Solutions for Version Control”. Subversion (SVN) is one of the popular and open Source Configuration Management tools. It is a centralized system. SVN consists of a centralized repository database and several command line tools. Large projects use SVN where multiple individuals work on the same code base, however, SVN can manage personal projects as well.
Before going into details, let’s try to understand few terminologies first.
A repository is a central database in SVN where we store all our versioned artifacts. It keeps a history of all versioned files. We can create a repository on a server or on a local PC. Front-end version control tool acts as clients of the repository. The client connects to the repository and then can read, write, modify the files in the repository. The changes made by the client in the repository become available to other people using the same repository.
Working copy is a private copy of specific revision of the central repository. It helps us to work easily and efficiently on the local machine. Working copy is a private workspace for every developer. So the developer can work independently from other people using the same repository.
Commit/ Check-in and Update/ Check-out
While people use working copy and work in isolation from the rest of the team, they also need to upload their changes in a central repository so the rest of the team can get their changes. Commit is the process of uploading the changes back into the central repository. The other team can synchronize their working copy with latest changes by updating their working copy. Checkout is a process of updating working copy.
A trunk is the main development directory where developers check-in all latest changes. Usually, the trunk directory maintains the main line of development.
Branch is created from the trunk or another branch and used to maintain a separate line of development. Developers create a branch when they want to work on multiple features or bug fixes simultaneously. In addition, the branches can be merged later into the trunk or another branch.
The tag is a read-only snapshot of the project. When developers want to store particular revision they create a tag of the repository (or selected files/directories in the repository) by giving a distinctive name.
To set up configuration management system, we need to install Subversion and front-end GUI tool. There are multiple installers available. Subversion is a multi-platform system and it is developed as a project of the Apache Software Foundation. Binary packages for different operating systems are available for download on Apache website. following six options available for Windows system.
- CollabNet (supported and certified by CollabNet; requires registration)
- SlikSVN (32- and 64-bit client MSI; maintained by Bert Huijben, SharpSvn project)
- TortoiseSVN (optionally installs 32- and 64-bit command line tools and svnserve; supported and maintained by the TortoiseSVN project)
- VisualSVN (32- and 64-bit client and server; supported and maintained by VisualSVN)
- WANdisco (32- and 64-bit client and server; supported and certified by WANdisco; requires registration)
- Win32Svn (32-bit client, server and bindings, MSI and ZIPs; maintained by David Darj)
A repository can be set up on a server (remote or local) and usually exposed by an Apache HTTP server or by svnserve server. In this post, we will see how to setup local repository using svnserve server on Windows. Download subversion binaries for windows from CollabNet. I am using Subversion 1.9.7 Windows 64bit version.
Installation of Subversion is straightforward. Run the installer and follow instructions.
Collabnet Subversion Installation step 1: Click Next button
Collabnet Subversion Installation step 2: Click Next button
Collabnet Subversion Installation step 3: Set installation location. I prefer something shorter like C:\svn. If you like you can keep default destination folder path.
Collabnet Subversion Installation step 4: Press Finish button once installation is complete.
Now we are ready to use Subversion. with command line tool. Subversion installer automatically updates system environment variable PATH with correct path of Subversion executable.
Create First Repository
Let’s create our first repository using subversion command line. The svnadmin is a server-side utility comes with Subversion. The svnadmin utility is used to create or manage repository. Run command prompt as administrator and execute the following command.
svnadmin create "c:\svnrepo"
This command will create a new repository with name ‘svnrepo‘ on C drive. It will create following files and directories.
svn repository files and directories
conf folder contains configuration files and hook scripts. We can modify these files but one should not modify these files manually. You can use the svnadmin tool to make any necessary change in your repository.
db folder in the repository contains the implementation of the versioned file system. The file system begins with revision 0.
svnserve server behaviour can be controlled by changing settings in svnserve.conf file under conf directory.
Open svnserve.conf file in notepad.
Prohibit read and write access to repository for unauthenticated user by setting anon-access = none
Allow complete read-write access to repository for authenticated used by setting auth-access = write
Specify the location of password database file by setting passwd-db = passwd. Note that the file’s location path is relative to the directory containing the configuration file. so the above setting means password database is stored in passwd file under conf directory.
Now we can add some users to the conf/passwd file. open this file in notepad and add usernames and passwords as shown below.
harry = harrysecret
sally = sallysecret
mohan = xyz123
Now our repository is ready to use and the above listed 3 users can access the repository.
To access the repository, our svnserve server must be running. we can register the Subversion svnserve as a Windows service by using Window’s Service Control utility. Execute following command.
sc create svnserve binpath= "c:\svn\svnserve.exe" --service -r c:\svnrepo
displayname= "Subversion" depend= Tcpip start= auto
This command will set the Subversion task as an auto start when the computer restarts. Start this service by issuing following command.
net start svnserve
Now the service is running, we can access repository. Let’s add a root level folder to our repository.
svn mkdir svn://localhost/MyProjects
Subversion will open an editor like Notepad to make us enter check-in comments. Enter comments and close the editor. SVN will ask credentials. Use the credentials setup in the conf/passwd file. After that, you will see a commit success message. This means our svnserve server is ready and working.
TortoiseSVN is a Subversion GUI client. It integrates with Windows Explorer. Download TortiseSVN installer. I am using TortoiseSVN 1.9.7(64bit). This installation also straightforward.
TortoiseSVN installation Step 1: Click Next button
TortoiseSVN installation Step 2: Read user agreement and click Next button
TortoiseSVN installation Step 3: Keep the default selections. Set installation location and click Next button.
TortoiseSVN installation Step 4: A progress bar will be shown during the installation process.
TortoiseSVN installation Step 5: Click Finish button once installation is complete.
Now we have a Subversion client installed, the next step we can do is to create a working copy. To create a working copy create a project folder. I created F:\MyProjects. TortoiseSVN is integrated with Windows Explorer so it can be easily accessed by right-clicking anywhere and select required context menu.
Right click on ‘Project” folder and select “SVN Checkout”
SVN Context menu
A dialogue box will appear. Add our repository URL. In this case, we are using localhost svnserve server, so URL is svn://localhost/myproject. Subversion allows us to check out a specific revision from the repository. Select head revision for now as we do not have many revisions available and click OK button.
SVN Checkout Dialogue Box
You will see a checkout successful message.
SVN Checkout Successful
Now you can see SVN working copy created on our local machine at folder F:\MyProjects.
Let’s add something to the repository. Subversion guidelines suggest basic folder structure. trunk, tag, and branches are the three directories should be created at project root level. We will start with creating these 3 folders in our local working copy. Then select them and right click. Chose Add from SVN context menu.
Add artifacts to repository
You will see a Tortoise SVN Add dialogue box like one shown below.
Tortoise SVN Add dialogue box
Select artifacts to be uploaded into version control and click OK button. Then you will see an Add finished message box.
TortoiseSVN Add Finished
Once we add a file or folder in the repository, we will see a blue plus sign overlay which indicates that the artifact is added to SVN local copy for version control.
Our files are still not included in the repository. To add our files to the repository, we need to commit our changes. Select artifacts which you want to upload in the repository and then right-click. Go to SVN context menu click SVN commit.
You will see a TortoiseSVN commit dialogue box. Add appropriate revision comment and click OK button to upload selected files to the repository. Now you will see a green checkmark overlay which indicates that the files are unchanged and same as checked out revision.
Subversion current copy