我想检查预提交挂钩中SVN提交消息中是否存在字符串“XYZ”。我试过下面的代码:
setlocal enabledelayedexpansion
set REPOS=%1
set TXN=%2
set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"
SET M=
REM Concatenate all the lines in the commit message
FOR /F "usebackq delims==" %%g IN (`%SVNLOOK% log -t %TXN% %REPOS%`) DO SET M=!M!%%g
if [[ $M == * "XYZ"* ]] then
goto NORMAL_EXIT
else
:ERROR_TOO_SHORT
echo "Commit id missing .Please enter the commit id in the format [XYZ - number]";
goto ERROR_EXIT
:ERROR_EXIT
fi
REM All checks passed, so allow the commit.
:NORMAL_EXIT
exit 0
但是当我在SVN中提交时,我现在意外地获得了$ M。我哪里错了?
编辑:它仅对此代码有效,
REM Make sure M is defined
SET M=0%M%
REM Here the 6 is the length we require
IF NOT "%M:~6,1%"=="" goto NORMAL_EXIT
:ERROR_TOO_SHORT
echo "Commit note must be at least 6 letters" >&2
goto ERROR_EXIT
:ERROR_EXIT
exit /b 1
如果我尝试修改它以使用if..else检查字符串,那么它会中断。