Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
Created February 5, 2010 14:16
Show Gist options
  • Save FilipDeVos/295816 to your computer and use it in GitHub Desktop.
Save FilipDeVos/295816 to your computer and use it in GitHub Desktop.
Subversion Hooks
@echo off
FOR /D %%I in (*) DO (
echo Installing hooks in %%I
copy pre-revprop-change.bat %%I\hooks\ /Y
copy pre-commit.bat %%I\hooks\ /Y
)
@echo off
:: Stops commits that have empty log messages.
setlocal
rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2
SET SVNLOOKPATH="C:\Progra~2\Visual~1\bin\svnlook"
rem check for an empty log message
call %SVNLOOKPATH% log %REPOS% -t %TXN% | findstr . > nul
if %errorlevel% gtr 0 (goto err) else exit 0
:err
echo. 1>&2
echo Your commit has been blocked because you didn't give any log message 1>&2
echo Please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1
@ECHO OFF
setlocal
:: Store all the parameters in variables.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5
SET SVNLOOKPATH="C:\Progra~2\Visual~1\bin\svnlook"
:: prevent author and date from getting changed.
if /I "%propertyName%"=="svn:author" goto ERROR_PROPNAME
if /I "%propertyName%"=="svn:date" goto ERROR_PROPNAME
if /I not "%propertyName%"=="svn:log" goto :eof
:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%"=="M" goto ERROR_ACTION
:: Make sure that the new svn:log message is not empty. the find command is used to capture stdin.
:: Unfortunately, when the message is empty the batch file terminates here without returning the
:: clean message. Seems to be related to how SVN calls the hook.
set bIsEmpty=true
FOR /F "tokens=*" %%g in ('find /V ""') do ( set bIsEmpty=%%g )
if "%bIsEmpty%"=="true" (
goto ERROR_EMPTY
)
FOR /F "tokens=*" %%a IN (%SVNLOOKPATH% author "%repository%" -r %revision%') DO set REV_USER=%%a
if %userName%==%REV_USER% (
goto :eof
)
FOR /F "delims== tokens=1*" %%a IN (%repository%\..\authz-svn.conf) DO if "%%a"=="svn_owner" ( set SVN_OWNER=%%b )
set bIsOK=false
FOR %%a IN (%SVN_OWNER%) DO if "%%a"=="%userName%" ( set bIsOK=true )
if "%bIsOK%"=="false" (
goto ERROR_AUTHOR
)
goto :eof
:ERROR_AUTHOR
echo You must be the author of the log message or owner of the repository %userName%. 1>&2
goto ERROR_EXIT
:ERROR_EMPTY
echo Empty svn:log messages are not allowed. %bIsEmpty% 1>&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo Changes to svn:author and svn:date are not allowed. 1>&2
goto ERROR_EXIT
:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. 1>&2
goto ERROR_EXIT
:ERROR_EXIT
exit /b 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment