Search
Translations of this page:

Setting up a post-commit mail notification for a Subversion repository

Post-commit notifications allow an email to be sent out to one or more users every time a commit is recorded to an Subversion repository. These messages will contain information about the commit such as who was responsible for committing the change, the log message, and a diff indicating what changes were made.

While these messages can be convenient, they can also be extremely large. Active repositories will also generate lots of commit messages. Be sure that you have your users' permission before subscribing them to any commit notifications.

You may also want to look into services such as CIA.vc, which can coexist with email-based commit notifications and allow users to receive similar information via an RSS feed or IRC.

While Virtualmin includes support for automatically setting up post-commit notifications, as of September 2007 this functionality is broken. Do not enable the email feature under Virtualmin's Subversion menu. Instead, follow the instructions below.

Creating a post-commit hook

To set up email notification of Subversion commits, first make sure that your Subversion repository has been created using Virtualmin.

Once you are sure that your repository exists, create a file called post-commit in your repository's hooks directory. For an example named <repository>, this file would exist at either ~/svn/<repository>/hooks/post-commit, or ~/domains/<yourdomain.com>/svn/<repository>hooks/post-commit.

To do this via SSH using the nano editor, one would use the following command:

nano ~/svn/reponame/hooks/post-commit

This file should have the following contents, replacing to-mail@domain.tld, from-mail@domain.tld, and reply-to@domain.tld with their respective values:

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "to-addr@domain.tld" \
 --from 'SVN @ your-domain.com <svn@your-domain.com>'

Normally, the to-mail@domain.tld would be set to the address for a dedicated Mailman mailing list. Be sure that the svn@your-domain.com alias exists and forwards to a site administrator.

The post-commit script needs to be executable by the www user, i.e. it needs to have executable bit turned on at least for your account group.

Setting the reply-to address

It is a good idea to set a Reply-To address pointing to the user who committed each change. This will allow users to easily send feedback on changes from their mail client.

To do this, create a directory named ~/etc/svn-authors. Each file in this directory will map a SVN username to that user's email address. For each user you want to add, run the following command, replacing username with the user's local SVN username, and user@domain.tld with the user's email address:

echo -n 'user@domain.tld' > username

You will then want to replace the last line in the post-commit file created above with the following:

AUTHOR=`/usr/local/bin/svnlook author -r "$REV" "$REPOS"`
/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "to-addr@domain.tld" \
 --from 'SVN @ your-domain.com <svn@your-domain.com>' \
 --reply-to `cat "/users/home/<your_username>/etc/svn-authors/$AUTHOR"`

Be sure to replace <your_username> with the username you use to log into your shared accelerator account.

Sending a test email

You can test the script out without having to commit. Connect to your account via SSH, cd to the hooks directory and run:

./post-commit path/to/your/repos #

(where # is a valid SVN revision in your repository)

Broken post commit on older blastwave template

 
shared/kb/svn-postcommit.txt · Last modified: 2010/03/05 07:52 by jacques
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki