SVN Pre Commit Hooks

别来无恙 提交于 2019-12-22 11:05:18

问题


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

回答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:

>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 ...



回答2:


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



来源:https://stackoverflow.com/questions/564631/svn-pre-commit-hooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!