Merging a Subversion Branch With Trunk
A most confusing thing to do in subversion is to merge a branch with a trunk. One might need this in cases where the branch has grown and has to be made a trunk. Following is a step by step how-to on doing this the proper way.
1. Check out the trunk or update an earlier working copy of the trunk
svn co file:///repository/project/trunk project
2. Merge the branch with the working copy
svn co file:///repository/project/trunkfile:///repository/project/branches/branch project
The arguments are -
a) An initial repository tree (left side of comparison)
b) A final repository tree (right side of comparison)
c) A working copy to accept the differences as local changes
This means that you can also give version numbers, for example:
svn co file:///repository/project/trunk@100 file:///repository/project/branches/branch@114 project
3. Now that the merging is done, go into the working copy and commit the changes.
svn commit -m "merged branch@114 to trunk@100"
Merging is very important and of frequent use during version control.
Removing .svn Directories From Subversion Checkouts
Use the following command to remove .svn directories from unwanted subversion checkouts.
find -iname “.svn” | xargs rm -r $1
Alternatively, you can commit all recent changes and use svn export to get the current version without .svn directories.
Backup Subversion Repositories And Projects
After I decided to manage my PhD thesis and projects with subversion, the most important thing to consider was a proper backup strategy. I decided to go a bit overboard with it as it might save me some day. There are several ways to backup subversion and I decided to use all of them!
a. Using crontab and rsync to backup subversion
Read my earlier post on crontab if you are not familiar with it. Someday I will write about rsync as well. But for now read this if you are new to rsync. I use the following code to backup the entire subversion repository to my backup directory.
rsync -av --delete --progress /source_directory/subversion/ /destination_directory/backups/subversion_backup/
I used crontab to schedule the above job to run at midnight every day. In case something happens to the original subeversion repository, it is easy to retrieve data from this backup – just copy it to the original location!
b. Using the backup script from COLLABNET (the subversion guys)
The next technique it to use the python based backup script from subversion called hot-backup.py. This script can be used to make a backup of the latest version of the subversion repository. I used the following code to download the latest version from COLLABNET website and install it on my system.
wget http://svn.collab.net/repos/svn/trunk/tools/backup/hot-backup.py.in
mv hot-backup.py.in hot-backup.py
Once that is done, I had to make some configuration changes in the file. The following lines were changed
# Path to svnlook utility
svnlook = r"@SVN_BINDIR@/svnlook"
# Path to svnadmin utility
svnadmin = r"@SVN_BINDIR@/svnadmin"
to look like this
# Path to svnlook utility
svnlook = r"/usr/bin/svnlook"
# Path to svnadmin utility
svnadmin = r"/usr/bin/svnadmin"
The next step is to run the script check if everything is fine. I used the code below:
python hot-backup.py --archive-type=zip --num-backups=10 ~/source_directory/subversion_repository /destination_directory/subversion_backup/
The above code will make a hotcopy of the latest version of the subversion repository into the backup directory in zip format. A total of 10 backups will be maintained at a time, oldest one being deleted when new ones are added.
Once the backup was properly inspected I created a cron job to run this command at midnight every day.
c. Using the subversion ‘hotcopy’ command
This is a very simple technique as it uses the inbuilt ‘hotcopy’ command to backup the svn repository. Follow the command below to make a reliable incremental backup of your svn repositories.
svnadmin hotcopy /source_directory/subversion_repository /destination_directory/subversion_backup/
Create a cron job to schedule it.
Once you have your backup system in place, rest assured that your data are safe.
Installing Subversion With Apache and DAV In Ubuntu 8.10
Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS) [Wikipedia]
I have adopted subversion to manage my PhD thesis and other research related tasks. Here is how I setup SVN server on my Ubuntu 8.10 server.
Installing subversion
First of all, we need to install the necessary packages to put SVN on to the server
sudo apt-get install subversion libapache2-svn
Now that SVN in on the server, the next step is to create a user who has rights to manage SVN repositories.
SVN users and groups
There are severel ways to set permissions on the repository. As I already have a username, say ‘mark’, on my server, the best thing to do would be to create a group called ‘subversion’ and add myself to it. I am also planning to access my repositories via http, so it is necessary to add the user ‘www-data’ to the ‘subversion’ group. All this can be done by following the commands below.
sudo addgroup subversion
sudo adduser mark subversion
sudo adduser www-data subversion
Logout and login again before continuing further.
Creating a SVN repository
The next thing to do is to chose a location for creating SVN repositories. I like to create my repositories at /home/svn. Follow the commands below to create a SVN repository.
sudo mkdir /home/svn
sudo mkdir /home/svn/research
sudo svnadmin create /home/svn/research
This will create the repository ‘research’ under /home/svn. Note that this repository will/should have the root:root user and group permissions.
Configuring SVN access via WebDAV protocol (http://)
To access the SVN repository via WebDAV protocol, configure the Apache2 web server. To do this edit the /etc/apache2/mods-available/dav_svn.conf file to look like:
DAV svn
SVNPath /home/svn/research
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/svn/htaccess
Require valid-user
Now WebDAV has to be provided with the user access details as it is going to control the reading and writing to the repository:
cd /etc/svn
sudo htpasswd -c -m htpasswd mark
Any additional users has to be added without the ‘-c’ switch so as to avoid overwriting the ‘htaccess’ file. Afterword restart apache by issuing:
sudo /etc/init.d/apache2 restart
Test the configuration by typing http://localhost/svn in a browser. Enter the username and password and now the repository can be seen.
Creating further repositories and projects
Further repositories may be constructed inside the research repository, provided users of the ‘subversion’ group should have their ownership. The following commands can achieve the same.
sudo mkdir /home/svn/research/thesis
sudo chown -R mark:subversion /home/svn/research/thesis
sudo chmod -R 777 /home/svn/research/thesis
svnadmin create /home/svn/research/thesis
Once that is done, its time create a project and add it to the repository so that SVN can manage it. Before that, its better to have a look at the ‘usual’ subversion project directory structure [Refer figure]. In SVN, a project directory usually has 3 subdirectories; trunk, tags and branches. Trunk contain the most recent working copy of the project, tags contain copies of the working directory of some importance (such as the copy of the thesis version that was submitted to your supervisor to have a look at) and branches contain snapshots of the working copy from which you decided to follow a different route.
All said, the final decision about the directory structure rests upon the user. Now the idea is to create a skeletal directory structure somewhere in your home directory and import it to the thesis repository. Follow the commands below to establish this.
cd ~
mkdir thesis
mkdir thesis/trunk
mkdir thesis/tag
mkdir thesis/branches
svn import thesis/ http://localhost/svn/research/thesis/
Now check repository again via the browser and project can be seen added inside. The skeletal directories can be deleted now. A working copy of the project can be created by issuing the commands:
cd ~
svn checkout http://localhost/svn/research/thesis
Files can be added to the repository by:
cd ~ cd thesis/trunk/
touch File_A.py
svn add File_A.py
svn commit -m "Initial import of the File_A.py file for versioning"
Check again via the browser to see the file.









