Email Notifications with Subversion
- Running SubVersion 1.4.2 on CentOS 5.5 (x64)
- For this guide, my repository is located at
- I’ll be using
- The former is more configurable and can be used on a per-directory basis. This is useful if you have many projects in a single repo.
Copy over the sample
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
hooks/post-commit and add this line:
/usr/share/doc/subversion-1.4.2/tools/hook-scripts/mailer/mailer.py commit "$REPOS" "$REV"
Comment out these lines:
commit-email.pl "$REPOS" "$REV" email@example.com log-commit.py --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:
[general] mail_command = /usr/sbin/sendmail smtp_hostname = localhost [defaults] 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 = firstname.lastname@example.org to_addr = email@example.com firstname.lastname@example.org reply_to = email@example.com generate_diffs = add copy modify show_nonmatching_paths = yes suppress_deletes = yes [maps]
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
firewall_scripts folder. In that case:
[firewall_scripts] for_paths = ^firewall_scripts($|/) commit_subject_prefix = "[SVN - Firewall Scripts]" from_addr = firstname.lastname@example.org to_addr = email@example.com
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 :)