Subversion notes

Subversion server died the other day, and I haven’t been backing it up. I use mediatemple for my hosting and they offer subversion so I thought I would start using it. Last time I got a friend to set it up for me but this time I thought I should do it my self. I know subversion is great, but it is also quite complex, I found it a complete nightmare, but I now have something that vaguely  approximates working.

The goal was to move all my local files that used to belong to the previous repository to a new repository hosted on my mediatemple server. Then get netbeans talking to it, and, hopefully have a clue how it all works. This proved to be a complete nightmare and so before I forget all the things I learned I will try and get down as many of them as possible here.

General Points

  • Subversion allows for repositories at the top level with multiple projects under that. This is what I have done.
  • The svn server stores everything in a folder I named svn – you don’t really want to go looking around it as far as I can tell.
  • Items have an address within the repository that looks something like this:
    protocol://host.com/folder/to/the/repository/svn/myRepo

    The path needs to be from the root of the host and the protocol can be several things depending on where you are accessing from. When accessing locally, i.e. you are on the same machine that hosts the repository you should use something akin to this (notice that there is no host, we don’t need it because we are on the machine in question).

    file:///home/max/svn/myRepo

    If however you are accessing a mediatemple hosted subversion repository you need to access it via svn+ssh which is the svn protocol tunnelled through ssh. In this case the path would look like this:

    svn+ssh://myhostname.com/home/1234/users/max/svn/mtSvnRepo1

    or

    svn+ssh://myusername@myhostname.com/home/1234/users/max/svn/mtSvnRepo1

    The only difference being the inclusion of the username that you wish to use with the host (your username for logging into the machine hosting the repository). More about that later. Now this is just the path to the repository, your projects and the files within them are then just bolted on the end thus.

    svn+ssh://myhostname.com/home/1234/users/max/svn/mtSvnRepo1/project1/src/someFile.java

Some Commands

  • Create a repository
    svnadmin create --fs-type fsfs
  • Import some files into the repository
    svn import /just/a/folder svn+ssh://myhostname.com/home/1234/users/max/svn/mtSvnRepo1 -m "a test of adding a new project remotly"

    the -m flag is the commit message which is stored with the revision number

  • List the projects under svn control
    svn list --verbose svn+ssh://myhostname.com/home/1234/users/max/svn/mtSvnRepo1
          2 maxgarfi              Jan 10 15:12 RAVisualisationClient-01/
          4 maxgarfi              Jan 10 15:20 RAVisualisationDataAccess-01/
         18 maxgarfi              Jan 10 18:30 RAVisualisationEngine-01/
          8 maxgarfi              Jan 10 15:32 RAVisualisationGUI-01/
         10 maxgarfi              Jan 10 15:37 RAVisualisationLib-01/
         12 maxgarfi              Jan 10 15:49 RAVisualisationServer-01/
         19 maxgarfi              Jan 10 19:00 librarys/
  • Checkout or co. Unlike Team Foundation or Source Safe on windows this doesn’t lock any files it just gets the latest copy from the repository.
  • Add – adds a new file to the repository.
  • Delete – removes the file from the repository (sort of) and only removes it from the repo when you commit.
  • Update – pulls down any changes to the files in the repo and tries to merge them with the local files on your machine.
  • Commit  - submits your changed files to the repo and gives them a revision number.

Removing Files From Subversion Control

No this really caught me out. When you associate files with a subversion repository the subversion client on your local machine peppers the folders of your project with hidden .svn folders. This is how it knows what is what and keeps track of stuff. BUT, and this is a big but, if you end up with a dead/no longer accessible repository and you want to move you local files so they are looked after by a new repository, then your in trouble. Its worth noting that at this stage you have lost all the previous history of your files – that went with the previous repository, but hey at least you have your files.

Try just adding these files to a new repository? It aint gonna work – subversion will tell you that they are being looked after by a now non existent repository. Took me a long time to find it but there is a subversion command that “exports” the files in your projects without all the hidden .svn files, and its called export:

 svn export /path/to/old/project/ path/to/new/version/

Great! just one little snag to look out for: if there were files in your project that you hadn’t added to the repo before it all went tits up export wont copy them over – you might need to hunt them down manually and copy them over to your new location.

SSH details

To get netbeans working with svn+ssh there was a fair bit of fafing around, there is a good page on the netbeans site. You also need to set up passwordless ssh access to the subversion server and possible create a .ssh/config file where you can specify the username to use when ssh’ing to that host.

Links


About this entry