Skip to content
Ahmed Hammad BlogA small bird flying along a dashed path

Sending Subversion Commit Information by Email

Sending Subversion Commit Information by EmailOn each commit, I want to send email with the commit details to a list of emails.
This is necessary to keep everyone involved updated. We are using subversion version
control system on windows, we use cygwin extensively to automate frequent tasks.
Here are the steps to do so:

Environment:
– Windows XP Service Pack 2
– Cygwin DLL release version is 1.5.23-2
– email version 2.5.0
– subversion 1.0.6

Sending email:
– The email.exe tool is a nice small tool to send email using sendmail or using other
SMTP server, I use it to send through our company SMTP server.
– First install cygwin, and you must select additional email tool from the email group.
After installation you will have a shortcut on your Desktop.

After download and installation are OK, you need to configure the email tool before using it.
>From now on, I will put $ before each command line, simply this is the bash prompt. You get bash prompt
by running cygwin shortcut on your PC Desktop.

$ email-config
You will be prompted with a series of questions, answer it to setup the email configuration file.

Please enter your From: name (e.g., John Doe) [Your Real Name]:
Please enter your From: email address [yourlogin@example.com]:
Please enter your Reply-to: email address []:
Enter 1 to use sendmail or 2 to use a SMTP server [1]:
Please enter the address of your SMTP server [127.0.0.1]:
Please enter the SMTP port number [25]:
Please select SMTP authentication (1 for none, 2 for LOGIN, 3 for PLAIN) [1]:
Please enter your SMTP username []:
Please enter your SMTP password []:

$

You can look at /etc/email/email.conf to review your selections and update them as needed.

You can have a look at email man pages by typing, it will show you all the switched used by email tool.
$man email

you can test by sending email to yourself:
$echo “This is a test email body message” > email.txt
$email -s “subject test 1” me@mycompany.com < email.txt

– The first line create file email.txt with the string “This is a test email body message”, of course you can use your favorite editor.
– The second line will just send the email taking the email body from the input stream through “<email.txt”

Now we need to catch svn commit to generate helpful message about the commit and send to email list.

Edit the file c:svnreposmyprojecthookpost-commit.bat using your favorite editor, I assume you locate your repository on c:svnreposmyproject

Add the following lines to it:

SET PATH=%PATH%;c:cygwinbin;C:subversionbin;
svn log -v -r “%1” svn://rd-cdma1/myproject > email.txt
svnlook diff “c:svnreposmyproject” -r “%1” >> email.txt
email -s “Subversion – %2 – %1” email1@company.com,email2@company.com < email.txt

– The PATH environement variable must be set to your programms pathes, I assume c:cygwinbin;C:subversionbin; You must use the correct values that match your system.
– The post-commit.bat will be called every time someone committed new code, this is per subversion implementation.
– %1 is the repository name, automatically passed to the post-commit.bat from subversion.
– %2 is the revision number, automatically passed to the post-commit.bat from subversion.
– > is the redirection operator used to create and append the output to a file.
– >> is the redirection operator used to append at the end of file.
– We use hard coded repository path and URL as the passed parameter %1 has backslashes which doesn’t work on Windows.

Conclusion:
Using command line tools is very helpful in automating tasks, many of the tasks done by admins requires automation, although GUI is very easy to use at first, you will continue doing things manually. command line give you powerful ways to automate new tasks without developing code which takes much more time.

Resources:
– Get cygwin from http://www.cygwin.com/
– Get subversion from http://subversion.tigris.org/

From ahm507.blogspot.com

Comments

Comments are closed. These were left on the earlier version of this blog.

Anonymous

Thanks A Hammad

Anonymous

I executed the steps of sending the email when commit and the email was sent successuflly when commited but the commit details not sent.

Ahmed Hammad

Adjust the path of repository and run the following one line command:
svnlook diff "c:svnreposmyproject" -r "%1" >> email.txt

Ensure the file email.txt contains your commit details.

Anonymous

This comment has been removed by a blog administrator.

Anonymous

Many thanks for your recommendations,i modify the path and the detailed of commit is sent.

Anonymous

$ email -s "Hello" mhossam@sewedy.net.eg < email.txt
email:FATAL : Could not connect to server:192.168.50.3 on port :25:connection refused
caught an ERROR,Shutting down …
– The previous is the message that appeared when I tested the email after executes the steps of sending the email, Can you help me to be able to successfully send the email through the network.

Ahmed Hammad

It is clear a connectivity error to email server.

Anonymous

Emergency Funds through Your Phone. Do you urgently need to borrow money for an emergency situation Find out where.

Anonymous

The author of ahm507.blogspot.com has written an excellent article. You have made your point and there is not much to argue about. It is like the following universal truth that you can not argue with: Blind compliance or compulsive non-compliance of anything are like the two sides of the same coin due to ignorance. Thanks for the info.