How to require commit messages in VisualSVN server?

Ben Collins picture Ben Collins · Oct 29, 2008 · Viewed 25.7k times · Source

We've got VisualSVN Server set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN as clients on our workstations.

How can you configure the server to require commit messages to be non-empty?

Answer

sylvanaar picture sylvanaar · Aug 12, 2009

I'm glad you asked this question. This is our pre-commit hook script written in common Windows Batch. It denies commit if the log message is less than 6 characters. Just put the pre-commit.bat to your hooks directory.

pre-commit.bat

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 NORMAL_EXIT

:ERROR_TOO_SHORT
echo "Commit note must be at least 6 letters" >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

REM All checks passed, so allow the commit.
:NORMAL_EXIT
exit 0