SVN Post-Commit to Laconica

Since I am using Laconica to capture notices from my batch jobs(see Microblogging for Applications) I thought it would be nice to add an account for my Subversion repositories and use the post-commit hook to keep me posted.

I’m not an expert with Subversion so if there is an easier way to get this information please let me know. I use two executions of the svnlook command to get the info and then dirs-changed for the folders involved.  My repositories are structured by projects so the first folder is the project name.

This example uses Window batch files:


:: *************************************************************
:: * this sets the arguments supplied by Subversion            *
:: *************************************************************

:: *************************************************************
:: * Call your batch file*
:: *************************************************************
CALL Drive:\path\to\batchfile.bat %REPOS% %REV%


setlocal enabledelayedexpansion
:: take the path and revision from the post-commit hook and use svnlook to gather info


:: Get Repository name from REPOS path
for /f "tokens=1,2,3,4  delims=/ " %%a in ("%REPOS%") do SET REPOSNAME=%%c

:: Build the svnlook commands
SET INFOCMD=Drive:\path\to\subversion\bin\svnlook info -r %REV% %REPOS%
SET DIRCMD=Drive:\path\to\subversion\bin\svnlook dirs-changed -r %REV% %REPOS%

:: Get USR from Info line 1 and MSG from line 4
SET /a counter=1
FOR /f "usebackq delims=" %%a in (`%INFOCMD%`) DO (
if "!counter!"=="1" SET USR=%%a
if "!counter!"=="4" SET MSG=%%a
set /a counter+=1

:: Get folder from dirs-changed ... only need the first line
FOR /f usebackq  %%a IN (`%DIRCMD%`) DO (
SET  DIR=%%a
GOTO GetProject

:: Get project name from DIR ... it is the first folder
for /f "tokens=1 delims=/ " %%a in ("%DIR%") do SET PROJECT=%%a

CALL twittercurl.bat "#%PROJECT% updated by #%USR% in the #%REPOSNAME% repsoitory. %MSG%"

The CALL to twittercurl.bat is described here: Microblogging for Applications

Please post any corrections and ideas!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: