Windows上的SVN预提交挂钩未按预期运行

时间:2013-07-15 08:37:22

标签: windows svn pre-commit errorlevel svnlook

我正在尝试为Windows编写一个预提交钩子.bat脚本。代码粘贴在下面。它运行文件直到我在下面写“问题”这一行。我想要做的是检查文件中是否有任何内容正在签入。我的期望是,如果findstr能够在文件内容中找到console.log,则ERRORLEVEL将打印值0,如果在文件内容中找不到console.log,则ERRORLEVEL将打印1.但令我惊讶的是,它总是打印0而不管是否在文件中找到console.log。请帮助了解我的问题在哪里。

由于

SET REPOS=%1
SET TXN=%2

REM check for blank svn log comments.
"svnlook.exe" log -t %TXN% %REPOS% | FindStr [a-zA-Z0-9]
IF %ERRORLEVEL% EQU 0 GOTO OK
    echo "commit comments are required" >&2 
exit 1
:OK

REM extract list of files to be committed into temp.txt file.
"svnlook.exe" changed -t %TXN% %REPOS% >c:\temp.txt

SETLOCAL EnableDelayedExpansion
SET count=1
REM loop thru each line of the temp.txt file.
FOR /F "tokens=* delims= usebackq" %%x IN ("%c:\temp.txt%") DO (

    REM Split it into token delimited by SPACE. Second token is a file name.
    for /f "tokens=1,2,3 delims= " %%a in ("%%x") do set d=%%a&set fileName=%%b

        REM get the content of the file and redirect into 1.txt
        "svnlook.exe" cat -t %TXN% %REPOS% !fileName! >c:\1.txt 
        REM "ISSUE HERE" find console.log string in the content 
        type c:\1.txt | FindStr "console.log"
        REM just print return value of above command. But ERRORLEVEL always prints 0 regardless of above findstr command finds "console.log" successfully or not. 
        echo errorlevel: %ERRORLEVEL% >&2

    SET /a count=!count!+1
)
ENDLOCAL


exit 0

0 个答案:

没有答案