Wednesday, 22 July 2009

Setting up Subversion post-commit hooks to send emails on Solaris 10

In previous post I explained how I set up some Subversions server on Solaris 10:
Now I want to tell you how I set up Subversion post-commit hooks to automatically send emails after commit events.


Intercepting Subversion events

Subversion lets you hook programs to be executed when certain events are fired. The current version of Subversion lets you hook into:
  • pre/post commit
  • pre/post lock
  • pre/post revprop-change
  • pre/post unlock
If you have a look into your repository base directory, you should see a hooks directory probably filled up with templates. Depending on the platform the executable scripts naming may vary. In the case of Solaris, and an UNIX platform in general, you can drop in an executable or a shell script named post-commit and Subversion will execute it after a commit operation.


Post-commit hook parameters

Subversion passes the following positional parameters to the hook scripts:
  • repository path
  • revision number (after the commit)
If you want, you can use these parameters to customize the behavior of your hook script. I personally use them to customize the subject field and the contents of the email I send.


An example script

I always use a layer of indirection if it makes sense to me. In this case I chose to do the same and my example script just invokes another one, passing by the parameters received by Subversion. No secrets, here, just a one liner.


Sending emails

The problem now reduces to sending email from your host. This may depend on your system configuration and on your tastes. You could use mailx, mutt or even sendmail directly. The Subversion developers suggest using their mailer.py to send emails. Setting it up is pretty easy and you'll also find a configuration file and some tests on Subversion website.

No comments:

Post a Comment