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
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:
Btw, it easier to write
This way you script is also stable against the ominous:
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 errorlevelsyntax 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: