Email Notifications with Subversion



Copy over the sample post-commit hook

Permissions and ownership are vitally important here!

cp hooks/post-commit.tmpl hooks/post-commit  
chmod 770 hooks/post-commit  
chown apache:apache hooks/post-commit

Now edit hooks/post-commit and add this line:

/usr/share/doc/subversion-1.4.2/tools/hook-scripts/mailer/ commit "$REPOS" "$REV"

Comment out these lines: "$REPOS" "$REV" --repository "$REPOS" --revision "$REV"

Configure email alerts for a repository

First copy over the sample mailer config:

cp /usr/share/doc/subversion-1.4.2/tools/hook-scripts/mailer/mailer.conf.example conf/mailer.conf

A general file looks like this:

mail_command = /usr/sbin/sendmail  
smtp_hostname = localhost  
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s  
commit_subject_prefix = "[SVN - IT Scripts]"  
propchange_subject_prefix =  
lock_subject_prefix =  
unlock_subject_prefix =  
from_addr =  
to_addr =  
reply_to =  
generate_diffs = add copy modify  
show_nonmatching_paths = yes  
suppress_deletes = yes  

The various options should be self-explanatory. A test commit should work at this point.

Configuring alerts for specific folders

Let’s say that a specific group of people is to know if commits are made to the firewall_scripts folder. In that case:

for_paths = ^firewall_scripts($|/)  
commit_subject_prefix = "[SVN - Firewall Scripts]"  
from_addr =  
to_addr =

Testing things out

You don’t necessarily need to commit things to test out the config.

sh hooks/post-commit /home/svn/repository 195

Where the last two arguments are the path to the repo and the revision number.

Tip of the Iceberg

There are tons of things you can do with mailer.conf in a large and/or complicated setting. The best way to get acquainted with its features is to essentially read the default file to figure out what it’s capable of. Reading others’ config files also helps :)