How to Get Email Notifications from Subversion on Commits

I recently was asked by some guys on my team if it was possible to get email notifications for every commit to svn with a description of what was removed, what was committed and a diff if possible. Now it seems like this would be easy and maybe even built into subversion so I checked into that first. There was a ruby script which can be made as a hook-script which is supposed to send email notifications. I spent quite some time trying to get it to work and didn’t have much luck so I decided to research some other options. I ran across a python program which was written specifically for this task called svnmailer.

Below I will detail the steps needed to get svnmailer working on your system:

The first thing we need is to make sure we have pysvn:

root@redmine:~# python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svn

If you do not get a error it means you have pysvn installed and it is working. If you get some sort of error you may need to download and install it.

I used 1.5 at the time of this article which I grabbed from here

Lets install it:

root@redmine:~#tar xvzf pysvn-1.5.0.tar.gz
root@redmine:~#cd pysvn-1.5.0/Source
root@redmine:~#python configure
root@redmine:~#mkdir /usr/lib/python2.4/site-packages/pysvn
root@redmine:~#cp pysvn/ /usr/lib/python2.5/site-packages/pysvn
root@redmine:~#cp pysvn/ /usr/lib/python2.5/site-packages/pysvn

Once you get that installed you should be able to run the imort svn command again and this time it will return to the python prompt with no errors.

NOTE: Pysvn maybe available in the package manger of your distro so check that first.

The next thing we need to do is download and install svnmailer:

Go here and download the version of svnmailer you want to use. I used 1.0.8 since it was the most recent stable version.

Lets install it:

root@redmine:~#tar xvzf svnmailer-1.0.8.tar.gz
root@redmine:~#cd svnmailer-1.0.8
root@redmine:~#python install

NOTE: Once again you package management system may have svnmailer so check that first

I am assuming that you already have a repo installed so for the sake of this article we will pretend the repo is called “myrepo” and is located at /var/svn/

The next thing to do is create the hook script:

cd /var/svn/myrepo/hooks

If there is a file called post-commit open it up in a editor, if it is not there simply create it.

Place the following text in the file:



# These are passed in by subversion

"${MAILER}" --commit 
            --config "${CONFIG}" 
            --repository "${REPOS}" 
            --revision "${REV}" 

Save this file and then give it the following permissions:

chmod 755 post-commit

Next we need to configure the conf file for svnmailer:

I created mine in /etc/svn-mailer.conf. Create the file and paste in the following text:

# the diff command to be used ... just copy it...
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
# the sendmail location
mail_command = /usr/sbin/sendmail

for_paths = myrepo/.*
# the subject of the email
commit_subject_prefix = "SVN COMMIT:"
# From address in the mail
from_addr =
# To address ...
to_addr =

# this part of the config apply for all the other module
# Default From address template
from_addr =
# the subject of the email
commit_subject_prefix = "SVN COMMIT:"
to_addr =
generate_diffs = add copy modify
suppress_deletes = yes

Obviously you will need to change the path to the repo, the from email and the send to email to fit your set up.

Next lets test our set up:

cd /var/sv/myrepo/hooks
./post-commit /var/svn/myrepo/ 366

You will need to replace the /path/to/repo ad the revision number to work for you but once this command is run, subversion should get a email with the contents of revision 366.

Now once a commit is made you will get an email . You can also add more than one email on the to_addr line, just separate each one with a space.

Version Control With Subversion for Subversion 1.6: The Official Guide And Reference Manual (Paperback)

List Price: $30.00
New From: $58.22 USD In Stock
Used from: $13.22 USD In Stock

Version Control with Subversion (Paperback)

List Price: $39.99 USD
New From: $14.18 USD In Stock
Used from: $0.01 USD In Stock