Automate Email Notifications for Subversion (SVN) Commits

The Problem

I want SVN to automatically send out notifications every time some one commits.

The Solution

I have used svn-mailer before and love its ability to configure the email contents as well as subject. This time I am interested in the DIY approach to learn more about SVN, so I did it without svn-mailer.

The first step is to go to my svn repository (/var/svn in this case) and create a script call post-commit in the hooks directory. Subversion looks for this file, so the name must be exact. The script must be executable. Here it the contents of /var/svn/hook/post-commit:


AUTHOR=$(svnlook author -r $REV $REPOS)
DATE=$(svnlook date -r $REV $REPOS)

    echo "REPOSITORY:   $REPOS"
    echo "REVISION:     $REV"
    echo "DATE:         $DATE"

    echo ""
    echo "DESCRIPTION:"
    svnlook log -r $REV $REPOS

    echo ""
    echo "FILES:"
    svnlook changed -r $REV $REPOS

} | mail -s "PerfPortal Check In Rev $REV by $AUTHOR" email_alias...

Now, every time someone checks in, Subversion will invoke the post-commit script with the path to the repository as the first parameter and the revision number as the second.


The script employs two tools to accomplish its objective: svnlook to retrieve various information regarding the committed revision and mail, the Unix command-line utility to send out email. I assume that your system is set up to allow sending email.

  • Line 3-4 identify the parameters Subversion passes to this script, namely the path to the repository and the revision number.
  • Line 5-6 determine the name of the person who committed the code and on which date
  • Line 9-20 display various information regarding the commitment. These information are piped into the mail command on line 22, thus become the body of the email.
  • Line 16 displays the comment the submitter entered when that person committed the code
  • Line 20 displays a list of files that are affected in this commitment.
  • Line 22 invokes the mail command to send out the notification. The -s flag specifies the subject. Replace email_alias with a list of email aliases separated by spaces.


Enabling Subversion commit notification is straight forward: all you have to do is to create a script which sends email with various information regarding the commitment. The script’s potentials do not limit to sending email, it can start unit tests modules, start build processes, update log files, and other tasks–use your imagination.

Another alternative to writing the script is to use tools such as svn-mailer. However, as with most of the tools, you do need to invest some initial time to learn about the tool to fully exploit its capacity

12 thoughts on “Automate Email Notifications for Subversion (SVN) Commits

  1. eeek

    Hi I tried your approach after svn-mailer fail to work. It’s working great but how can I differentiate between different project under this repository? For eg.

    – projectA/
    – src
    – …
    – projectB/
    – src
    – …

  2. Hai Post author

    @Georgekutty: I don’t use Windows, I am sorry I don’t know the answer to your question. I hope others can help you out.

  3. jay


    i noticed when i set the email notifications to .html, it generates logs into a log there a config setting to delete them after the notification?


  4. Gopal

    Can you please help how to write the script for sending mail when some one commit from specific path?
    Where should i input the specific path(Branches\Project_A) in this script?

  5. Hai Post author

    @Gopal: I have no longer have access to any SVN server to try out your request, but what you want to do is looking up `svnlook changed` and parse that contents.

  6. Raushan

    i want to send mail to few person based on our our work-space project.
    I mean, For each project i want send mail to different group of people.

    If possible then where i should give this condition?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s