I come from a background of using Visual Source safe as a tool for source control and had never really needed to setup a source control infrastructure prior to my assignment in Pakistan. So when I landed the job, I quickly downloaded and installed the Collabnet build of subversion. Then decided that like any software development team worth its salt, I would have to create software coding practices and procedures and one of which was the use of source control and thus formulated rules around checking in source code such as No check ins without comments, All comments must make sense blah blah blah. Later during my analysis of the check ins I realised that my team members were going against rules and were checking in code without comments or just lazy comments like “fixed” or “done” or “checked in” at which point I came to a crossroad – do I lay down the law at them for doing this or do I find an automated way of resolving this matter and I decided the later had a more long lasting effect – plus it stretched us, which is good. So I did my research and discovered that it was not direct provided (not a config change) but was possible by using hooks.
I created a file that had a bunch of excluded words as mentioned above saved it in c:\svn\excludedwords.txt and then created a pre-commit batch file that was supposed to be run prior to committing the change(duh!). The exact filename was Pre-commit.bat that was placed in the Hooks folder on SVN
The contents of the batch file were
rem Make sure that the log message contains some text.
set REPOS=%1
set TXN=%2
"C:\svn\SVNlook.exe" log -t %TXN% %REPOS% | FindStr [a-zA-Z0-9]
IF %ERRORLEVEL% EQU 0 GOTO OK
echo Your commit has been blocked because you didn't provide a 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
:OK
rem Check if comment is in list of reserved words to not be used..
the above is meant to check for empty comments and would echo out correct error messages.
"C:\svn\SVNlook.exe" log -t %TXN% %REPOS% >comment
setlocal enabledelayedexpansion
Set SEPARATOR=
set COMMENT=
for /f "delims=" %%a in (comment) do (
set currentline=%%a
set COMMENT=!COMMENT!%SEPARATOR%!currentline!
)
FIND "%COMMENT%" "c:\svn\excludedwords.txt">Null
If %ERRORLEVEL% EQU 1 goto OK2
:Fail
echo Your commit has been blocked because the single word comment you provided is not allowed 1>&2
echo Line is -%COMMENT%- 1>&2
echo Please write a proper log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1
:OK2
rem Check that the author of this commit has the rights to perform
rem the commit on the files and directories being modified.
rem commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
rem All checks passed, so allow the commit.
exit 0
The above was used to check if the comment was a single word or found in my excluded list of words.
So I quietly sneaked in the change and waited for responses, I got a few moans but explained later that it was important to follow rules.