Subversion post-commit hook E-mail report script that sends the diff as an attachment

I’m using the post-commit hook to send out E-mail notifications when changes are committed to Subversion repositories.

If you search the web you’ll find a ton of scripts in various languages for this purpose. They all do more or less the same thing: create an E-mail message for the commit, including such details as the revision author, number, timestamp, a list of the paths that were changed, and a diff of the changes.

For one particular project I wanted the diff as an attachment, though, rather than inline in the message text. So I ended up writing my own script. It’s a Shell script that should work on most Unix/Linux based systems.

Source code

Installation instructions

To install this for your repository:

  1. Copy commit-report.sh to the server hosting your repository, for instance to /usr/local/bin, and make sure it’s executable (run chmod +x commit-report.sh)
  2. Check line #2 of commit-report.sh – you may need to change that address depending on your individual circumstances I removed this item later: see this comment
  3. Edit line #2 of the file post-commit: change /path/to to the correct path for your server, e.g. /usr/local/bin
  4. Edit line #2 of the file post-commit: you probably don’t want to send reports to foo and bar at foo.local but to some other address(es)
  5. If you want a fancy name in the subject line, instead of “SVN: `basename-of-your-repository`” append -name "Your fancy name here" to line #2 in post-commit
  6. If you haven’t used the post-commit hook yet, copy the file post-commit to the hooks directory in your repository – Note: Don’t check it in, but copy it to the respository itself, e.g. in /srv/svn/repositories/myrepo/hooks
  7. If you’ve already used the post-commit hook, and it’s a Shell script, append line #2 of the file post-commit to your script. If it’s not a Shell script you’ll have to figure out a way to call commit-report.sh with the correct parameters in your language

You can always test commit-report.sh by invoking it manually.

Troubleshooting

Update: Pointers for troubleshooting have been added later, based on your feedback…

  • If the script runs without any errors on the console, but you never receive a commit report, change line #2 of commit-report.sh: put something like FROMADDRESS="youremail@yourdomain" in here

Tags: , , , ,

  1. What is an example of what I put in this line:

    FROMADDRESS="svn@`hostname --fqdn`"

    I have several repositories on my server and I am not sure, do I replace the hostname with the IP address? My repositories are located at svn://ipaddress/repo1, svn://ipaddress/repo2, etc.

  2. Hi svn newbie,

    Most of the time that line should remain unaltered. The portion in backticks is a so-called external command, i.e. it is executed and then replace by the output of the command. If you run hostname --fqdn you’ll get something like “myserver.mydomain.tld” so that line would end up doing the same as FROMADDRESS="svn@myserver.mydomain.tld"

    If and only if sending using that address causes any issues you should put a different E-mail address in there. If you just replace the word “hostname” you’ll most likely break the script and get an error message.

    In any case you shouldn’t put the server’s IP address here; an E-mail address such as “svn@192.0.2.42” will not work as expected in most cases.

    Update: I just noticed that my instructions might have been confusing. I updated the post accordingly.

Reply

Your email address will not be published.