I’m using the post-commit hook to send out E-mail notifications when changes are committed to Subversion repositories.
If you search the web you’ll find a ton of scripts in various languages for this purpose. They all do more or less the same thing: create an E-mail message for the commit, including such details as the revision author, number, timestamp, a list of the paths that were changed, and a diff of the changes.
For one particular project I wanted the diff as an attachment, though, rather than inline in the message text. So I ended up writing my own script. It’s a Shell script that should work on most Unix/Linux based systems.
Source code
Installation instructions
To install this for your repository:
- Copy
commit-report.sh
to the server hosting your repository, for instance to/usr/local/bin
, and make sure it’s executable (runchmod +x commit-report.sh
) Check line #2 ofI removed this item later: see this commentcommit-report.sh
– you may need to change that address depending on your individual circumstances- Edit line #2 of the file
post-commit
: change/path/to
to the correct path for your server, e.g./usr/local/bin
- Edit line #2 of the file
post-commit
: you probably don’t want to send reports to foo and bar at foo.local but to some other address(es) - If you want a fancy name in the subject line, instead of “SVN: `basename-of-your-repository`” append
-name "Your fancy name here"
to line #2 inpost-commit
- If you haven’t used the post-commit hook yet, copy the file
post-commit
to thehooks
directory in your repository – Note: Don’t check it in, but copy it to the respository itself, e.g. in/srv/svn/repositories/myrepo/hooks
- If you’ve already used the post-commit hook, and it’s a Shell script, append line #2 of the file
post-commit
to your script. If it’s not a Shell script you’ll have to figure out a way to callcommit-report.sh
with the correct parameters in your language
You can always test commit-report.sh
by invoking it manually.
Troubleshooting
Update: Pointers for troubleshooting have been added later, based on your feedback…
- If the script runs without any errors on the console, but you never receive a commit report, change line #2 of
commit-report.sh
: put something likeFROMADDRESS="youremail@yourdomain"
in here
Tags: diff, email, hooks, notifications, svn
-
What is an example of what I put in this line:
FROMADDRESS="svn@`hostname --fqdn`"
I have several repositories on my server and I am not sure, do I replace the hostname with the IP address? My repositories are located at svn://ipaddress/repo1, svn://ipaddress/repo2, etc.
2 comments
Comments feed for this article
Trackback link: https://ten-fingers-and-a-brain.com/2012/01/subversion-post-commit-hook-e-mail-report-script-that-sends-the-diff-as-an-attachment/trackback/