Dea*_*ean 3 svn batch-file pre-commit findstr svn-hooks
我目前正在尝试扩展我们已经存在(并且正在工作)的预提交批处理文件,以便提交到SVN.第一部分阻止任何没有注释并按预期工作的提交.第二部分是阻止用户提交SUO文件的attmept,但是这当前阻止了所有提交.
我对DO脚本的理解不是很好,所以我怀疑它可能是我对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
Run Code Online (Sandbox Code Playgroud)
如果找到了某些东西,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
Run Code Online (Sandbox Code Playgroud)
顺便说一句,写起来更容易
if errorlevel 0 andthencontinuewithwhatever
Run Code Online (Sandbox Code Playgroud)
这样你的脚本也可以对抗不祥之物:
set errorlevel=0
Run Code Online (Sandbox Code Playgroud)
然后将以正确的方式销毁任何以%errorlevel%打印出错误级别的尝试.
(编辑)重要说明:我忘了说if errorlevel语法检查errorlevel是否大于或等于要测试的值.因此,要正确使用它,您必须始终首先检查最高错误,例如:
someCommand
if errorlevel 10 ...
if errorlevel 9 ...
if errorlevel 0 ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3791 次 |
| 最近记录: |