Subversion Hooks

For my non-technical friends, Subversion is a tool for keeping track of changes to files and documents. It's free and it's very good. You can find it at http://svn.collab.net/. For my more technical friends, there's some interesting features that take some work to configure. I'm going to talk today about hooks.

Hooks

Hooks are little scripts or programs that run before or after you commit a change to the repository (where subversion keeps the files). They'll help you prevent bad changes from going in, or track changes in different ways. I recently installed a hook to send an email to people when a change is committed to the repository . You can, but don't need to, write your own hooks. There are some good ones already written.

The one that's driving me crazy is a hook called svnperms.py. It lets you configure more granular permissions on what you can and can't do. For instance, the convention in repositories is to have a trunk folder for your main files, a branches folder for working with files on the side, and a tags folder where you mark a set of files for future reference (like a bookmark). The rules say that you should only create tags and not update or delete them. svnperms helps make that happen.

svnperms.py

Installing the hook is sometimes trivial, but I had a few obstacles:

My first problem was that svnperms is written using the python language. That wasn't really the problem. T problem was that the system I was installing to doesn't have python. Not a big problem though - I had the system admin install it.

The installation of svn doesn't really have a standard location for hook scripts. You'll have to come up with your own. I copied mine into a separate folder and then just pointed my calls to them in the right direction. Once I had everything where I thought it would go, my first test couldn't find python. I was a bit stumped because I thought it was defined in the PATH environment. Apparently, it's not that simple. I needed some help, so I asked StackOverflow for help. I ended up setting the PATH explicitly in the script.

svnperms.conf
My biggest complaint about svnperms is that the documentation sucks. It's not really there. I'm not writing this as a replacement for the missing docs, but hopefully I can help someone else who is fighting with it.

There's a configuration file called svnperms.conf. It's there to define permissions. There are sections and groups that you define. Like the authz file, groups places users into groups. Sections define permissions for those groups.

You can have multiple groups and sections, but it appears that the section name needs to match the repository name - or something. I have a repository named Sandbox. I named a section [sandbox] and it complained that it couldn't find it. So I named it [Sandbox] to match the case of the repository and it seemed to work. There's nothing I can find documented that shows that behaviour.

There's a reference to a dead website (http://moin.conectiva.com.br/RepositorySystem) that is supposed to explain it all. The site isn't even available from the wayback machine.

My next trick will have to be to learn Python and trace the code by hand.