1

Windows 用の pre-commit フック .bat スクリプトを作成しようとしています。以下にコードを貼り付けます。以下に「ISSUE HERE」と書いた行までファイルを実行します。私がやろうとしているのは、チェックインされているファイルにコンテンツがあるかどうかを確認することです。私の期待では、findstr がファイルの内容で console.log を見つけることができる場合、ERRORLEVEL は値 0 を出力し、console.log がファイルの内容で見つからない場合、ERRORLEVEL は 1 を出力します。 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