SVN Page

From CUC3
Revision as of 13:34, 31 October 2006 by import>Jss43
Jump to navigation Jump to search

Catherine suggested that we put all the bits and pieces we learn about SVN in one place. A jolly good idea as I do tend to forget about things!


As a CVS user, migrating to SVN was not without it's hiccoughs. Let's begin with some technical details:

Setting up your SVN details

(1) If you've got an account on the SVN server at WWMM, you should have a certificate file need by SVN to authenticate a session. Let's call this file svn_cert.p12. Place it in a convenient place, say, $HOME/certificates/

(2) Now edit the file $HOME/.subversion/servers It should contain the lines:

[groups]
wwmm = wwmm.ch.cam.ac.uk
                                                                                
[wwmm]
ssl-client-cert-file = $HOME/certificates/svn_cert.p12
ssl-client-cert-password = <the password Catherine gave you>

I'm not sure if you have to put your password there, but if you do, SVN won't prompt you for a password each time you try to use it.

(3) I found it convenient to define an environment variable pointing to my SVN directory on the WWMM server:

SVN=https://wwmm.ch.cam.ac.uk/svn/users/am592
export SVN

You could just add those lines to your .bashrc file.

Now you are set.


Creating a Project

There seem to be a couple of ways of doing this. The method reccommended by the SVN book (Version Control with Subversion - O'Reilly) is to use svnadmin create. This won't work as none of us users have access to the svnadmin command. The following works quite well:

$ svn mkdir $SVN/project1

This will create directory project1 in the repository. The svn mkdir command can also be used to make a directory in your working copy, but more on this later.

Now your project has its own directory on the SVN server. Let's get the files into it.

$ ls my_code
a.f90  b.f90
$ svn import my_code $SVN/project1
Adding     my_code/a.f90
Adding     my_code/b.f90
Committed revision 1.

That's done. Notice that the project is called my_code in my directory but project1 on the server. The names could be the same.

Differences

It's exceptionally useful to check the difference between a local file and the repository version. svn does provide svn diff, but this uses the standard diff engine, which is somewhat unhelpful. You (apparently) can change your diff engine (e.g. to xxdiff) in your ~/.subversion/config file, but I have never got this to work. Instead, I wrote a function using svn cat in my ~/.bashrc which does the job:

svndiff () {
    if [ "$#" -eq 0 -o "$1" == "-help" -o "$1" == "--help" ];    then
        echo "Usage: svndiff <file> [-r revision_number]"
        echo "Compare local copy to specified revision in the subversion"
        echo "repository (default: last commit) using xxdiff."
    else
        tempfile='\tmp\`basename $1`
        svn cat $@ > $tempfile
        xxdiff $1 $tempfile
    fi
}

The servers do not have xxdiff installed, but they do have vimdiff, which works similarly as above. You can pass flags through such as revision number, so long as they come *after* the filename.

--jss43 12:34, 31 October 2006 (GMT)