Click here to Skip to main content
13,399,624 members (48,421 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 19 Jul 2012

Adding Post-commit Hook to SVN Source Control

, 28 Jul 2012
Rate this:
Please Sign up or sign in to vote.
How to add a post-commit hook to SVN source control that sends email to the team


Tortoise SVN is a free source control tool that is used by many. One of the things I find missing is email notifications on check-in or commit (as it is called in SVN). Here, I try to share how we can send email notifications on commit.

The code presented in this article sends an automated email to predefined list of people with details about files that were checked-in/committed.


While working in a team, it is possible that two or more people are working on different but interdependent code blocks. For instance, one person working one data layer of the application may have changed the method signatures in the classes. Now, the person working on business layer will be affected since his code is outdated.

So, instead of people running to each others seats or typing emails about the code changes they have performed, it can be time saving to have automated emails.

An automated build is another step that could be added to the post commit hook (I intend to update the current code with that step later).

Using the code

I intend to keep it as a installation manual and will try to tell step by step process to use the executable and configuration file. If you are not interested in the code details, avert.

This code uses two worth mentioning classes:

  • Process
  • SmtpClient

Before we get into the details, lets step back and see what SVNLook.exe provides us with. This executable is provided with the VirtualSVN server and lets user examine the transactions that have occurred. This executable can be used to diagnose the issues that may have occurred in the source control. Here, we are using this to identify the most recent commit details.

The program executes two commands using SVNLook.exe. First, to get the author information. Following C# code executes a command returns the username for the person who performed last commit operation on a given repository (branch, if you are VSS/TFS friendly):

svnLook = new Process();
svnLook.StartInfo = new ProcessStartInfo();

svnLook.StartInfo.FileName = Settings.Default.SVNLookFilePath;
svnLook.StartInfo.Arguments = "author " + Settings.Default.RepositoryPath;
svnLook.StartInfo.UseShellExecute = false;
svnLook.StartInfo.RedirectStandardOutput = true;

string consoleMessage = string.Empty;

consoleMessage = svnLook.StandardOutput.ReadToEnd();

This message will later be used in the email content.

Next, we execute changed command to get the details of commit performed by aforementioned user.

svnLook.StartInfo.Arguments = "changed " + Settings.Default.RepositoryPath; 
consoleMessage = svnLook.StandardOutput.ReadToEnd();  

Once we have received the information, we would compose and send an email to the list of users. Following code sends the email to users:

mailMessage.From = new MailAddress(Settings.Default.FromAddress);
               mailMessage.Subject = Settings.Default.MailSubject;
               mailMessage.Priority = MailPriority.Low;
               foreach (var email in Settings.Default.ToAdress)
               mailMessage.IsBodyHtml = false;
               mailMessage.Body = mailContent;
               SmtpClient smtpClient = new SmtpClient();
               smtpClient.Host = Settings.Default.SMTPHost;
               smtpClient.Port = Settings.Default.SMTPPort;
               smtpClient.EnableSsl = Settings.Default.EnableSMTPSSL;
               smtpClient.Credentials = new NetworkCredential(Settings.Default.FromAddress, Settings.Default.FromAddressPassword);

You may have noticed the usage of Settings here in the code. Settings is an very easy way to keep things configurable in your application. Here is a MSDN link that tells more about it.

Weak Link

The current code version does not employ good exception handling and logging mechanism. Although, it may well be improved using Microsoft Enterprise Library's Exception Handling and Logging blocks. One may prefer to write his own library to efficiently perform these operations.

Using the executable

If you need to use the executable right away, here are the steps to follow:

Open SVNPostCommitHook.exe.config file and set the following

  • FromAddress: Email address from which email will be sent
  • MailSubject: Subject for automated email
  • ToAdress: Email addresses to which mail is to be sent (multiple addresses can be added)
  • SMTPHost: Name/IP of the host used for SMTP transaction
  • SMTPPort: Port number used for SMTP transactions
  • EnableSMTPSSL: Sets whether SMTP transactions should be carried out over https
  • FromAddressPassword: Password for email address from which mail will be sent
  • LogFilePath: Path of the log file. All the error information will be logged into this file
  • SVNLookFilePath: Path of SVNLook.exe file
  • RepositoryPath: Path of repository for which hook is set
Once these settings have been updated, perform following actions in VirtualSVN server manger:

  1. Open
    VirtualSVN server manager. Right click on the repository for which post commit
    hook is needed. Click on Properties
  2. Switch to the second tab: “Hooks” on the properties
    window. Select “Post-commit hook” and click on edit.
  3. Paste
    the path for the executable file that will perform post commit
    work. Click on OK for all the windows.

Points of Interest

I am interested in writing more and more useful hooks for SVN and sharing it here at CodeProject.


Version 1.0


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Self Employed
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Generalunable to download source code Pin
deorerohan9-May-14 0:39
memberdeorerohan9-May-14 0:39 
GeneralRe: unable to download source code Pin
d@nish 9-May-14 0:46
member d@nish 9-May-14 0:46 
GeneralRe: unable to download source code Pin
d@nish 9-May-14 0:57
member d@nish 9-May-14 0:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180218.2 | Last Updated 28 Jul 2012
Article Copyright 2012 by lw@zi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid