Subversion Hooks Stored in the Repository

about | archive

[ 2009-January-05 21:50 ]

I am a proponent of the theory that everything for a project should be stored in a version control system. This lets you easily find all the files for a project, makes backups easy, lets you collaborate with others, or synchronize your work between multiple computers. I even spend time including third party dependencies, so all I need to do is check out the repository to get the project working. One of the more powerful features of version control systems are hooks, which let you run arbitrary programs as part of committing a change. For Subversion, it has always bothered me that the hooks are stored outside the repository. This means that you can't track changes to those scripts in the same way that you track the rest of the repository. Hence, I hacked a simple script to solve this problem. My post-commit hook script does the following:

  1. Checks out a directory in the repository into a temporary directory.
  2. Executes the "real" post-commit hook script stored in the temporary directory.
  3. Copies the latest version of itself over the previous version in the repository's hooks directory.

This lets you do a few things. First, you can put any scripts or configuration that your post-commit hook requires into a single directory, in your repository. Second, you can update the post-commit hook script itself. This means you can install this "bootstrap" post-commit script once, then update it just by checking in a new version. Of course, if you break it, you'll need to install it manually again. This same technique could very easily be extended to update all the hook scripts. Of course, this doesn't help with testing a hook script, which is still a pain in the ass.

Grab the script, modify the constants, copy it into your repository's hooks directory: