Question

I am trying to write a pre-commit hook .bat script for windows. Code is pasted below. It runs file till the line where I have written "ISSUE HERE" below. What I am trying to do in a is to check if there is any content in a file which is being checked-in. My expectation is that if findstr is able to find console.log in the file content ERRORLEVEL will print value 0 and if console.log is not found in the file content then ERRORLEVEL will print 1. But to my surprise it always prints 0 regardless of console.log found in the file or not. Please help to understand me where is the issue.

Thanks

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

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top