Subversion

Subversion

Gventure provides support for open-source Subversion version control tool. It is open-source and distributed as free software over the internet. It comes by default with most of the GNU/Linux distributions, so it’s in your system Might Be Already Installed. Subversion used to keep up present and verifiable variants of records, such as, source code, website pages, and documentation.

To svn installation follows these steps:

Step 1: Download Subversion: First download SVN from the following URL provides URLs about the latest stable releases of Subversion built by third parties for all major operating systems:

1
http://subversion.apache.org/packages.html

Step 2: check whether svn is installed or not, using following command.

1
[taylor@CentOS ~]$ svn –version
If Subversion client is not installed, then command will report error, otherwise it will display the version of the installed svn software.
1
2
[taylor@CentOS ~]$ svn --version
-bash: svn: command not found
Step 3: If you are using RPM-based GNU/Linux, then use yum command for installation.
1
2
3
[taylor@CentOS ~]$ su -
Password: 
[root@CentOS ~]# yum install subversion
After successful installation, execute the svn –version command.
1
2
3
[taylor@CentOS ~]$ svn --version
svn, version 1.6.11 (r934486)
compiled Jun 23 2012, 00:44:03
And if you are using Debian-based GNU/Linux, then use apt command for installation.
1
2
3
4
5
6
[taylor@Ubuntu]$ sudo apt-get update
[sudo] password for jerry:
[taylor@Ubuntu]$ sudo apt-get install subversion
[taylor@Ubuntu]$ svn --version
svn, version 1.7.5 (r1336830)
compiled Jun 21 2013, 22:11:49

Create Repository:
We have seen how to install Subversion client on GNU/Linux. Let us see how to create a new repository and allow access to the users.

Apache Setup:
On server we have to install Apache httpd module and svnadmin tool.

1
2
3
[taylor@CentOS ~]$ su -
Password: 
[root@CentOS ~]# yum install mod_dav_svn subversion

The mod_dav_svn package allows access to a repository using HTTP, via Apache httpd server and subversion package installs svnadmin tool.

The subversion reads its configuration from /etc/httpd/conf.d/subversion.conf file. After adding configuration, subversion.conf file looks as follows:

1
2
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so
1
2
3
4
5
6
7
8
<Location /svn>
   DAV svn
   SVNParentPath /var/www/svn
   AuthType Basic
   AuthName "Authorization Realm"
   AuthUserFile /etc/svn-users
   Require valid-user
</Location>

Let us create Subversion users and grant them access to the repository. htpasswd command is used to create and update the plain-text files which are used to store usernames and passwords for basic authentication of HTTP users. ‘-c’ options creates password file, if password file already exists, it is overwritten. That is why use ‘-c’ option only the first time. ‘-m’ option enables MD5 encryption for passwords.

Create user Setup:
Let us create user tom.

1
2
3
4
[root@CentOS ~]# htpasswd -cm /etc/svn-users tom
New password: 
Re-type new password: 
Adding password for user tom

Let us create user jerry.

1
2
3
4
5
[root@CentOS ~]# htpasswd -m /etc/svn-users taylor
New password: 
Re-type new password: 
Adding password for user taylor
[root@CentOS ~]#

Create Subversion parent directory to store all the work (see /etc/httpd/conf.d/subversion.conf).

1
2
[root@CentOS ~]# mkdir /var/www/svn
[root@CentOS ~]# cd /var/www/svn/

Repository Setup:
Create a project repository named project_repo. svnadmin command will create a new repository and a few other directories inside that to store the metadata.

1
2
3
4
5
6
7
8
9
[root@CentOS svn]# svnadmin create project_repo
[root@CentOS svn]# ls -l project_repo
total 24
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 conf
drwxr-sr-x. 6 root root 4096 Aug  4 22:30 db
-r--r--r--. 1 root root    2 Aug  4 22:30 format
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 hooks
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 locks
-rw-r--r--. 1 root root  229 Aug  4 22:30 README.txt
Let us change the user and group ownership of the repository.
1
[root@CentOS svn]# chown -R apache.apache project_repo/
Check whether SELinux is enabled or not using the SELinux status tool.
1
2
3
4
5
6
7
[root@CentOS svn]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted
For our server, SELinux is enabled, so we have to change the SELinux security context.
1
[root@CentOS svn]# chcon -R -t httpd_sys_content_t /var/www/svn/project_repo/
To allow commits over HTTP, execute the following command.
1
[root@CentOS svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/project_repo/
Restart the Apache server and we are done with the configuration of Apache server.
1
2
3
4
5
6
7
8
[root@CentOS svn]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: apr_sockaddr_info_get() failed for CentOS
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
[root@CentOS svn]# service httpd status
httpd (pid  1372) is running...
[root@CentOS svn]#
We have configured the Apache server successfully, now we will configure the repository. To provide repository access to only authentic users and to use the default authorization files; append the following lines to project_repo/conf/svnserve.conf file.
1
2
anon-access = none
authz-db = authz

Conventionally, every Subversion project has trunk, tags, and branches directories directly under the project’s root directory.

The trunk is a directory where all the main development happens and is usually checked out by the developers to work on the project.

The tags directory is used to store named snapshots of the project. When creating a production release, the team will tag the code that goes into the release.

The branches directory is used when you want to pursue different lines of development.

Let us create the trunk, tags, and branches directory structure under the project repository.

1
2
3
4
[root@CentOS svn]# mkdir /tmp/svn-template
[root@CentOS svn]# mkdir /tmp/svn-template/trunk
[root@CentOS svn]# mkdir /tmp/svn-template/branches
[root@CentOS svn]# mkdir /tmp/svn-template/tags
Now import the directories from /tmp/svn-template to the repository.
1
2
3
4
5
6
[root@CentOS svn]# svn import -m 'Create trunk, branches, tags directory structure' /tmp/svn-template/ 
Adding         /tmp/svn-template/trunk
Adding         /tmp/svn-template/branches
Adding         /tmp/svn-template/tags
Committed revision 1.
[root@CentOS svn]#

This is done! We have successfully created the repository and allowed access to Tom and Taylor. From now, they can perform all the supported operations to the repository.