free hit counter

Thursday, February 07, 2008

SVN email on commit

So getting SVN to email on commit was way harder than it should have been, but it was mostly this was because I'm running my SVN server under Windows.

I was running around in circles with the usual \r\n differences, but the real problem was finding a compliant command line email utility. mailsend was the first one that worked not just when I was logged in and testing, but more importantly when the Apache service kicked off the job.

My post-commit.bat file in the hooks directory:

@echo off
:: emails out the log message after a commit
perl d:\svn\ %1 %2 testing

My full perl script (which isn't working without the testing flag being set):

# Rian Sanderson
# Feb 7 2008
# First two inputs are standard issue from SVN
# Last argument is optional, and modifies the send to address so you
# don't start spamming your group with half baked emails
# Have users include a tilde (~) in their log messages for a quiet
# mode
# broken: does not work without testing flag
$repos=~ s/\\/\\\\/g;

if ($testingFlag) {
$debugLogName= "$repos/hooks/debug-log-post-commit-hook.txt";

$theTime= localtime time;
print DEBUGLOG "\n\n--$theTime\n";
print DEBUGLOG " $repos $rev\n";

$quietModeFlag=`svnlook log -r $rev $repos | grep '~'`;

if ($quietModeFlag ) {
if ($testingFlag){
print DEBUGLOG " not generating an email per the user's request.\n";
exit 0;

#create the subject
$numFiles=`svnlook changed -r $rev $repos | wc -l`;
$synopsis=`svnlook log -r $rev $repos | head -c 42`;
$synopsis=~ s/\s*$//;
$subject="\"[$rev] $numFiles files: $synopsis...\"";
#$subject="\"[$rev]: $synopsis...\"";
if ("$testingFlag") {
print DEBUGLOG " numFiles: $numFiles\n";
print DEBUGLOG " subject: $subject\n";

# create the body of the message
$bodyFile= "$repos/hooks/$rev.txt";
`echo >> "$bodyFile"`;
system("svnlook log -r $rev $repos > $bodyFile");
`echo >> "$bodyFile"`;
`echo >> "$bodyFile"`;
`echo "files changed:" >> "$bodyFile"`;
system("svnlook changed -r $rev $repos >> $bodyFile");
`echo "." >> "$bodyFile"`;

#ship it off
if ("$testingFlag") {
else {
$fromAddr= '';
#$mailCmd="blat $bodyFile -server -to $toAddr -from $fromAddr -subject $subject ";
$mailCmd="-d -smtp -t $toAddr -from $fromAddr -sub $subject -m $bodyFile,text/plain +cc +bc";
if ("$testingFlag") {
print DEBUGLOG " mailsend $mailCmd";

system("mailsend $mailCmd >> $debugLogName");

#dispose of the body
if (! $testingFlag) {



Post a Comment

<< Home