Vercingetorix Technologies

The Discussion Delegate

Answers to the Ultimate Questions about the Web, Mobile and Vercingetorix

Get emails from SVN on commit

This post was created on June 3rd, 2009 by admin and has 1 comment. It has been filed under , , , , , ,

We have been using SVN for a couple of years for all of our projects. Initially we were hosting them at Springloops.com for almost a year, when we decided to start hosting them on our own server.

It all sounded really good, till we realized that code reviews became a real problem. Springloops had a stunning interface to compare the diffs and get all the related information, which we really missed.

So we decided to use the post-commit hooks in SVN to email us as soon as a commit was made.

If you would like to implement the same for your server, here is a quick and dirty guide on how to do that.

First, the details about our server

# svn --version
svn, version 1.5.1 (r32289)
compiled Jul 31 2008, 09:45:20

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid

Okay, so let us get started. The first thing that you should know is that inside your repository, SVN creates a folder called hooks. This folder initially contains template files for all the hooks that can be called via SVN. The hook that we are after today, is called post-commit.tmpl

Since our language of preference is PHP, we decided to call a php script as soon as a commit was done on that repository. Here is how we did it

# cd /path/to/repo/hooks
# mv post-commit.tmpl post-commit
# chmod 755 post-commit
# vi post-commit

The post-commit file contains the following

#!/bin/sh

REPOS="$1"
REV="$2"

php /svn/scripts/postCommitHook.php $REPOS $REV

The above steps can also be automated by writing another php script which would copy all our hooks from a base directory into the respective directories in the repositories. Here is what our script looks like

Finally, we need to create the file postCommitHook.php which will find out all the relevant information and mail you the details. We have used svnlook and phpmailer to get all the information. Here is what our postCommitHook.php looks like

And that is it!

Once the scripts are in place, just run copyHooks.php once and then whenever anybody commits on any of your repositories, you will get an elaborate email with the diff.

Popularity: 7%

We are a Pune, India based firm specializing in building PHP, iPhone and Android applications. You can also catch our latest updates via RSS or follow us on Twitter. To invite us to work on a project, please get in touch via the Contact page and we'll get back to you at the earliest.

One Response to “ Get emails from SVN on commit ”

  1. [...] to the RSS feed for updates on this topic.Powered by WP Greet BoxWe finally managed to setup SVN to start sending us emails on each commit. I also wrote about it in more detail on the company [...]

Leave a Reply