1

我正在尝试为 Windows 编写一个预提交钩子 .bat 脚本。代码粘贴在下面。它运行文件直到我在下面写“ISSUE HERE”的那一行。我正在尝试做的是检查正在签入的文件中是否有任何内容。我的期望是,如果 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
4

0 回答 0