As I mentioned early I've been working on a SVN post-commit script. We've got a SVN repository that will be modified by several remote developers and I really need to keep an eye on this repository and I need to closely monitor changes to this repository.
There are two major functions that I needed in my post-commit script:
There are an abundant of examples showing off how to do this in various *nix flavors, but I couldn't find any good Windows-based solutions that didn't require Perl to be installed on the server. That led me to create the following post-commit.bat script.
@ECHO OFF REM ************************************************************* REM * this sets the arguments supplied by Subversion * REM ************************************************************* SET REPOS=%1 SET REV=%2 REM ************************************************************* REM * define directory paths * REM * you *must* add any paths for command line tools you plan * REM * since SVN does not include the Windows %PATH% environment * REM * variable for security reasons. * REM * * REM * DIR - the current hooks directory * REM * PATH - a user set path of where executables are located * REM * * REM ************************************************************* SET DIR=%REPOS%/hooks REM ************************************************************* REM * make sure to add the path to the SendEmail executable * REM ************************************************************* SET PATH=%PATH%;%DIR%;C:\Utils REM ************************************************************* REM * define the path to the working copy of your code * REM * * REM * the default working_copy folder would be: * REM * file:///%REPOS% * REM ************************************************************* SET WORKING_COPY=c:\path\to\working\copy REM ************************************************************* REM * define e-mail parameters * REM ************************************************************* SET SITENAME=My Code Base SET SMTP_SERVER=smtp.yourdomain.com SET EMAIL_TO=svnupdates@yourdomain.com SET EMAIL_FROM=svnupdates@yourdomain.com SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS% REM ************************************************************* REM * update the local working copy * REM * this will sync the new changes to your servers copy * REM ************************************************************* svn update %WORKING_COPY% REM ************************************************************* REM * generate the header to use for the e-mail message * REM ************************************************************* ECHO The following changes were made to the code: > %DIR%/email.txt ECHO. >> %DIR%/email.txt REM ************************************************************* REM * dump the log of changes to the e-mail message * REM ************************************************************* svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt REM ************************************************************* REM * dump the diff changes to the e-mail message * REM * * REM * WARNING: Generates tons of output * REM * * REM * NOTE: this is optional, you can remove this information * REM * if you do not want a verbose message of changes * REM ************************************************************* svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt REM ************************************************************* REM * send the e-mail message to the user * REM * * REM * NOTE: to create a SendEmail.log file, append: * REM * * REM * -l %DIR%/SendEmail.log * REM * * REM * at the end of the line below. * REM ************************************************************* sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt
A couple of notes on the script above:
If you have any problems getting this script working, I recommend you check out my blog entry on debugging SVN repository hook scripts in Windows.
86 Comments
Comments for this entry have been disabled.