Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN Pre Commit Hooks

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
like image 223
Dean Avatar asked Dec 13 '25 19:12

Dean


2 Answers

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 ...
like image 152
gimpf Avatar answered Dec 16 '25 13:12

gimpf


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

like image 35
Christian Studer Avatar answered Dec 16 '25 12:12

Christian Studer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!