Block commit to SVN when Redmine issue is not specified

Redmine allows to reference commits to issues by using keyword refs followed by # and number of the issue. If you want to block user commit to SVN without specifying Redmine issue you can use similar pre-commit hook on SVN. The hook is for Windows version.


@ECHO OFF

REM *************************************************************
REM * this sets the arguments supplied by Subversion *
REM *************************************************************
SET REPOS=%1
SET TXN=%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%

REM *************************************************************
REM * get comment search for "refs #" *
REM *************************************************************
svnlook log -t "%TXN%" "%REPOS%" | findstr /c:"refs #" > NUL
IF %errorlevel% NEQ 0 GOTO Error

GOTO Success

:Error
ECHO. 1>&2
ECHO Your commit has been blocked because you didn't 1>&2
ECHO specify Redmine issue with refs keyword. 1>&2
ECHO Please write a log message (eg. refs #123) and 1>&2
ECHO then try committing again. -- Thank you Roman 1>&2
EXIT 1

:Success

Leave a Reply

Your email address will not be published. Required fields are marked *