Skip to content

Instantly share code, notes, and snippets.

@utopius
Last active December 19, 2015 11:49
Show Gist options
  • Save utopius/5950220 to your computer and use it in GitHub Desktop.
Save utopius/5950220 to your computer and use it in GitHub Desktop.
Subversion / VisualSVN-Server batch pre-commit hook enforcing commit message length and forbidding addition of mergeinfo. Thx to HG :)
setlocal enabledelayedexpansion
set REPOS=%1
set TXN=%2
set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"
SET M=
REM Concatenate all the lines in the commit message
FOR /F "usebackq delims==" %%g IN (`%SVNLOOK% log -t %TXN% %REPOS%`) DO SET M=!M!%%g
REM Make sure M is defined
SET M=0%M%
REM Here the 6 is the length we require
IF NOT "%M:~6,1%"=="" goto MESSAGE_VALIDATION_PASSED
:ERROR_TOO_SHORT
echo "Sorry, commit message must be at least 6 letters. kthxbye :) ..." >&2
goto ERROR_EXIT
:ERROR_EXIT
exit /B 1
REM All checks passed, so allow the commit.
:MESSAGE_VALIDATION_PASSED
FOR /F "usebackq tokens=1,2*" %%i IN (`%SVNLOOK% log -t %TXN% %REPOS%`) DO (
REM U - Updated a file
REM UU - Update to file AND properties
IF %%i==UU GOTO checkmergetracking
IF %%i==_U GOTO checkmergetracking
)
EXIT /B 0
:checkmergetracking
%SVNLOOK% diff -t %TXN% %REPOS% | find "Added: svn:mergeinfo"
IF ERRORLEVEL 1 EXIT /B 0
ECHO "Sorry, addition of mergeinfo is not permitted on non-root folders. kthxbye :) ..." >&2
EXIT /B 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment