I wanted to check if a string "XYZ" in present in SVN commit message in pre-commit hook. I have tried below code :
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
But when i commit in SVN i am getting $M was unexpected at this time. Where am i going wrong ?
EDIT: it works good for this code only ,
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 i try to modify this to check string using if..else then it breaks.