• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

If you wish you can get notification right into your inbox when a team member commits the code. This mail will contain list of files added/deleted along with the svn diff of files that are modified. This needs some extra efforts to setup, but once it is setup it is very helpful.

This can be done by using svn hooks. Yes, svn has inbuilt hook functionality like pre-commit, post-commit, post-lock, post-unlock, pre-lock, pre-unlock, start-commit. We’ll use post-commit hook to get notifications.

First of all get a perl script from here http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in and copy it to hooks directory inside your repository directory, lets say /var/www/repos/repository_name/hooks.
Make sure to rename it as commit-email.pl, ofcourse you need perl installed on your server. Now cd to hooks directory inside you repository directory. Rename post-commit.tmpl to post-commit, and chmod 755 to post-commit and commit-email.pl . Now open post-commit in you favorite editor, and put “/usr/bin/perl /var/www/repos/commit-email.pl –from [email protected] -s ‘SVN commit notification’ ‘$REPOS’ ‘$REV’ [email protected], [email protected]” at the bottom of that file. Now open commit-email.pl and make changes in configuration section according to your requirement and server, specially svnlook path.

Congrats!, You are done ;-) .

Now your server will send email notification to [email protected], [email protected] whenever someone commits.


**For security reasons, the Subversion repository executes hook scripts with an empty environment that is, no environment variables are set at all, not even $PATH or %PATH%. Because of this, a lot of administrators are baffled when their hook script runs fine by hand,but doesn’t work when run by Subversion. Be sure to explicitly set environment variables in your hook and/or use absolute paths to programs.

It worked for me, Please let me know if it works for you too.

7 Responses so far.

  1. Gary says:

    I also use post-commit hook to svn update my repository automatically. Using the svnlook command to check which files were updated then traversing to the parent directory if multiple files were updated and doing an svn update at tha parent level :)

    Email hook is very handy.. I recommend trac too if you don’t already run it!

  2. [...] Some days ago I wrote a post about “SVN commit notification” which uses a perl script for sending commit notification with svn diff by mail. In this mail you can find svn diff from the last committed revision. I used to love this mail, soon I realized that it is a bit ugly and difficult to read. Also there were some important information missing. Like the name of user committing the code, the log message etc… [...]

  3. Douglas says:

    Thanks, this was very helpful.

    I found a couple of things had to be modified in the command in post-commit:
    a. email recipient addresses are not separated by commas
    b. the “$REPOS” and “$REV” should come before the options (–from, -s)
    c. your path to the commit-email.pl script should be /var/www/repos/repository_name/hooks/commit-email.pl

    Cheers!

  4. rms says:

    Hi all,
    I am also in need of installing this facility in my svn, but I could not find the file in the above link,Please help out…

    regards,
    rms…

  5. rms says:

    Hi all,
    I am also in need of installing this facility in my svn, but I could not find the file in the above link,Please help me out…

    regards,
    rms…

  6. ThoQuach says:

    Could we set ‘from’ value using the username of guys who commit?

  7. Shawn says:

    The original link does not work, but I found it in the following location: http://svn.collab.net/viewvc/svn-cvs/tools/hook-scripts/commit-email.pl?revision=1.4&view=markup
    However the file itself says it was committed a very long time ago, so I wonder if it still works as is or needs updating.


Asset Pipeline has been extracted a...

The asset pipeline which was introduced in Rails 3.1, has ...

ClientSideValidations: Add/Map mode...

#/status/256699237230845952

Action and Page caching has been ex...

With the commit c82cf81f00f Action and Page caching has been extracted ...

turbo-sprockets-rails3: Speeds up ...

#/status/253420357841723393

EdgeRails: ActiveRecord::SessionSto...

With the commit 3324e28804 ActiveRecord::SessionStore is extracted out of Rails into ...

Asset Pipeline has been extracted a...

The asset pipeline which was introduced in Rails 3.1, has ...

ClientSideValidations: Add/Map mode...

#/status/256699237230845952

Action and Page caching has been ex...

With the commit c82cf81f00f Action and Page caching has been extracted ...

turbo-sprockets-rails3: Speeds up ...

#/status/253420357841723393

EdgeRails: ActiveRecord::SessionSto...

With the commit 3324e28804 ActiveRecord::SessionStore is extracted out of Rails into ...