Friday, January 08, 2010

Send details of SVN commit on windows using DOS/Batch script

At work we have a shared SubVersion source code repository.  At the moment we don't have a CI setup for every project and I got fed up of not always knowing that someone had also checked something in. (CI sends build/test notifications - success and failure- so I know if something has changed that way.)
So I could make sure I was always notified of when someone else had changed something in a project I'm working on I set up a post-commit hook to send me an email.

The following is a post-commit hook script that I have written to enable me to keep track of what others are checking in.  I publish it here as I couldn't find a good example of this for Windows machines.

Please note that paths and email addresses have been changed to protect the guilty. You'll want/need to change these if you use a copy of this script yourself.

rem This hook sends an email when something is checked in to this repository

set REPOS="%1"
set REV=%2

"C:\Program Files\VisualSVN Server\bin\svnlook.exe" author %REPOS% -r %REV% > D:\SUBVERSION\MISC\author%REV%.tmp

set /p AUTHOR= D:\SUBVERSION\MISC\%REV%.tmp

echo. >> D:\SUBVERSION\MISC\%REV%.tmp

echo Who: %AUTHOR% >> D:\SUBVERSION\MISC\%REV%.tmp

echo. >> D:\SUBVERSION\MISC\%REV%.tmp

echo Comment:  >> D:\SUBVERSION\MISC\%REV%.tmp
"C:\Program Files\VisualSVN Server\bin\svnlook.exe" log %REPOS% -r %REV% >> D:\SUBVERSION\MISC\%REV%.tmp

echo. >> D:\SUBVERSION\MISC\%REV%.tmp

echo Changes:  >> D:\SUBVERSION\MISC\%REV%.tmp
"C:\Program Files\VisualSVN Server\bin\svnlook.exe" changed %REPOS% -r %REV% >> D:\SUBVERSION\MISC\%REV%.tmp


D:\SUBVERSION\MISC\sendemail.exe -f svn-checkin@example.com -t name@example.com -u "Check-in for REPOSITORY-NAME" -o message-file=D:\SUBVERSION\MISC\%REV%.tmp


del D:\SUBVERSION\MISC\author%REV%.tmp
del D:\SUBVERSION\MISC\%REV%.tmp

I also use rule in outlook to ignore notifications of check-ins made by me.

This uses SendEmail by Brandon Zehm (available at: http://caspian.dotconf.net/menu/Software/SendEmail/) as a command line tool to send emails from the script.

0 comments:

Post a Comment

I get a lot of comment spam :( - moderation may take a while.