SVN 预提交挂钩

发布于 2024-07-13 16:48:14 字数 562 浏览 12 评论 0原文

我目前正在尝试扩展我们已经存在的(并且正在工作的)预提交批处理文件以提交到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彻夜缠绵 2024-07-20 16:48:14

如果找到某些内容,findstr 返回 0;如果没有找到任何内容,则返回 1。 你刚刚倒置了你的支票。

不需要batch-foo,即使在Windows上,shell也是交互式的,所以你可以活着尝试一下:

>dir | findstr ".sln"
15.01.2009  16:37            33.844 Project.sln

>echo %ERRORLEVEL%
0

>dir | findstr ".slngimpf"

>echo %ERRORLEVEL%
1

顺便说一句,写起来更容易

if errorlevel 0 andthencontinuewithwhatever

这样你的脚本对于不祥的情况也很稳定:

set errorlevel=0

这将破坏任何未来打印出以正确的方式将错误级别设置为%errorlevel%。

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

someCommand
if errorlevel 10 ...
if errorlevel 9 ...
if errorlevel 0 ...

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 ...
笑,眼淚并存 2024-07-20 16:48:14

不完全是您正在寻找的答案,但您可以使用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文