views:

3099

answers:

3

I seem to be getting nowhere with this. Either searching the web for a script, etc. Anyone got a script that you can just edit the out-of-box pre-commit.tmpl in a Windows environment that requires x chars to be entered in for a comment on commit in Tortoise Subversion globally so that all members on the team are required whereas this requirement is pushed down to the clients from SVN server?

I don't know the scripting language and this should be something pretty damn simple without me taking the time to figure out scripting for the next 3 hours.

+14  A: 

This is a .bat file to require there is a comment. It checks for the existence of at least one character in the comment.

 @echo off  
 :: Stops commits that have empty log messages.        
 @echo off  

 setlocal  

 rem Subversion sends through the path to the repository and transaction id  
 set REPOS=%1  
 set TXN=%2           

 svnlook 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 enter a comment. 1>&2  
 echo Write a log message describing the changes made and try again. 1>&2
 echo Thanks 1>&2
 exit 1

This file sits in the /hooks folder of the repository, named pre-commit.bat. If you need a minimum amount of characters, the line to modify is

svnlook log %REPOS% -t %TXN% | findstr . > nul

So if you wanted a minimum of 10 characters, you need to have 10 .'s rather than just one

svnlook log %REPOS% -t %TXN% | findstr .......... > nul

More advanced options for the findstr command will let you do fancier checks (certain character sets, ect)

Corey Downie
I've seen that but it's not easy to modify when you don't know the syntax.
CoffeeAddict
even tried putting that in the hook for pre-commit (server-side) and my client was not forced to enter a comment anyway
CoffeeAddict
the key is in the svnlook line of the code. You will need to ensure you have a proper path to the svnlook command for this script to work.
Corey Downie
so if I want 100 chars I have to add 100 dots! are you serious?
CoffeeAddict
I don't know what you mean by proper path to the svnlook
CoffeeAddict
you paste the script in above to the pre-commit on server-side in that repository I'm working with and it still doesn't require comments to be entered...
CoffeeAddict
%1 must be a placeholder duh
CoffeeAddict
so what transaction ID do you specify or is that a placeholder subversion fills once it runs this hook?
CoffeeAddict
also, do you create the .bat and the .tmpl are for another language then and they don't run or what?
CoffeeAddict
Yes, 100 characters = 100 dots with that script. But you only have to do it once...You need to make sure that on the svn server, when you goto a command prompt and type 'svnlook' something happens. svnlook is a command line tool and you might need to have a path like 'c:\Program Files\...\svnlook' for the script to work depending on how your system's PATH variable is set up.1% and %2 are reading in the arguments that are passed to the hook from svn. We are assigning it to the REPOS, TSN variable for later use.
Corey Downie
+1  A: 

I use SubversionNotify, it probably does more than what you need, but is pretty simple to set up.

Slipfish
Looked at this, but don't see a way to limit comments or any regex syntax that shows you how in reference to this application.
CoffeeAddict
A: 

Try this :

rem Make sure that the log message contains some text. set REPOS=%1 set TXN=%2

"C:\Program Files\Subversion\bin\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 -------------------------------------------------------------
rem Check if comment is in list of reserved words to not be used..
rem -------------------------------------------------------------

"C:\Program Files\Subversion\bin\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:\Program Files\Subversion\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 -------------------------------------------------------------
rem Check number of words on the line if = 2 then reject comment
rem -------------------------------------------------------------
Set VAR1=%COMMENT%
Set count=0
For %%j in (%VAR1%) Do Set /A count+=1
IF %count% EQU 2 goto Fail2
goto OK3

:Fail2
echo Your commit has been blocked because not enough detail supplied 1>&2
echo Please write a longer log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1

:OK3
rem -------------------------------------------------------------
rem Check that the author of this commit has the rights to perform
rem -------------------------------------------------------------
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

Nick