Tech-Tidbit: Subversion Post-Commit Email
I was setting up an installation of subversion for a client (and I will be for myself soon here – it’s about time to move from CVS) and I needed to enable it to send an email to folks each time a commit was made. This tidbit assumes that you’ve already installed SVN on a linux machine.
First, you need to visit your hooks dir (created when you create a new repository (which is done using svnadmin)).
# cd /path/to/repo/hooks
You need to download a copy of the commit email perl script, which you can get from here.
# wget http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in
Then, rename it to .pl. You’ll need to rename the special file that SVN uses to activate the email. This file is post-commit.tmpl and you’ll need to rename it to post-commit.
# mv commit-email.pl.in commit-email.pl
# cp post-commit.tmpl post-commit
Next you need to edit the post-commit file so that it sends your email out. At the bottom of the file, add the following:
/path/to/repo/hooks/commit-email.pl "$REPOS" "$REV" --from svn@example.com "me@example.com" "you@example.com"
Then just save the file. Now you’re ready to test. You can either make a commit or run the below command. First call the post-commit, then provide the path to a repository to watch, then provide the revision number you want to run a test on. If you’ve just imported code and don’t have any other revisions, just provide the number 1 – but beware the possibility of a really long email.
# ./post-commit /path/to/repo 40
Things should be working fine by this point, but I ran into a problem. I saw the error message Global symbol "@SVN_BINDIR" requires explicit package. In that case, just go into the commit-email and change the @SVN_BINDIR variable on line 46 to the full path of svnlook.