views:

1009

answers:

2

I am currently trying to extend our already existing (and working) pre commit batch file for committing to SVN. The first part blocks any commit that does not have comments and works as expected. The second part is an attmept to block users committing SUO files, however this is currently blocking all commits.

My understanding of DOs scripting isn't great so I suspect it may be my usage of the FindStr?

Can anyone help?

"C:\Program Files\VisualSVN Server\bin\svnlook.exe" log -t %2 %1 | FindStr [a-zA-Z0-9]
IF %ERRORLEVEL% EQU 0 GOTO OK
echo "Commit Comments are Required" >&2
exit 1
:OK
"C:\Program Files\VisualSVN Server\bin\svnlook.exe" diff -t %2 %1 | FindStr /R "[a-zA-Z]\.suo"
IF %ERRORLEVEL% EQU 0 exit 0
echo "SUO files cannot be committed" >&2
exit 1
+3  A: 

Not exactly the answer you are looking for, but you can block all *.suo files with the global-ignores option.

christian studer
Voted up, definitely doesn't deserve -1.
Daniel
global-ignores is also a much better way to deal with the problem than pre-commit hooks. Though the real solution is to smack your developers with a clue by four untill they learn. See http://sirhc.us/journal/2007/07/27/oscon-2007-subversion-worst-practices/
Ronny Vindenes
+3  A: 

findstr returns 0 if something has been found, and 1 if nothing has been found. You just inverted your check.

No batch-foo required, even on Windows the shell is interactive, so you can try it out alive:

>dir | findstr ".sln"
15.01.2009  16:37            33.844 Project.sln

>echo %ERRORLEVEL%
0

>dir | findstr ".slngimpf"

>echo %ERRORLEVEL%
1

Btw, it easier to write

if errorlevel 0 andthencontinuewithwhatever

This way you script is also stable against the ominous:

set errorlevel=0

which will then destroy any future attempt to print out the errorlevel with %errorlevel% in a correct way.

(edit) Important note: I forgot to say that the if errorlevel syntax checks whether the errorlevel is greater or equal to the value being tested for. So to correctly use it, you must always check for the highest error first, like:

someCommand
if errorlevel 10 ...
if errorlevel 9 ...
if errorlevel 0 ...
gimpf