SVN 预提交挂钩
我目前正在尝试扩展我们已经存在的(并且正在工作的)预提交批处理文件以提交到 SVN。 第一部分阻止任何没有注释并按预期工作的提交。 第二部分是尝试阻止用户提交 SUO 文件,但这目前正在阻止所有提交。
我对 DOs 脚本的理解不是很好,所以我怀疑这可能是我对 FindStr 的使用?
有人可以帮忙吗?
"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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果找到某些内容,findstr 返回 0;如果没有找到任何内容,则返回 1。 你刚刚倒置了你的支票。
不需要batch-foo,即使在Windows上,shell也是交互式的,所以你可以活着尝试一下:
顺便说一句,写起来更容易
这样你的脚本对于不祥的情况也很稳定:
这将破坏任何未来打印出以正确的方式将错误级别设置为%errorlevel%。
(编辑)重要提示:我忘了说
if errorlevel
语法检查错误级别是否大于或等于 到被测试的值。 因此,要正确使用它,您必须始终首先检查最高错误,例如: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 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:不完全是您正在寻找的答案,但您可以使用
Not exactly the answer you are looking for, but you can block all *.suo files with the global-ignores option.