SVN预提交挂钩 [英] SVN Pre Commit Hooks

查看:165
本文介绍了SVN预提交挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试扩展我们已经存在(并且正在工作)的预提交批处理文件,以提交到SVN.第一部分阻止任何没有注释且可以按预期工作的提交.第二部分是阻止用户提交SUO文件的方法,但是当前正在阻止所有提交.

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.

我对DO脚本的理解不是很好,所以我怀疑这可能是我使用FindStr吗?

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如果发现某些内容,则返回0,如果未发现任何内容,则返回1.你刚把支票倒了.

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

即使在Windows上,外壳也是交互式的,也不需要batch-foo,因此您可以尝试以下方法:

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

这将破坏以后以正确方式打印出%errorlevel%的错误级别的任何尝试.

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

( edit )重要说明:我忘了说 if errorlevel 语法检查错误级别是否是更大或等于.被测试的价值.因此,要正确使用它,您必须始终首先检查最高错误,例如:

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

这篇关于SVN预提交挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆