diff --git a/bin/internal/shared.bat b/bin/internal/shared.bat index 97eee5a9b3..504540b230 100644 --- a/bin/internal/shared.bat +++ b/bin/internal/shared.bat @@ -52,18 +52,24 @@ GOTO :after_subroutine CALL "%bootstrap_path%" ) - REM Check that git exists and get the revision - SET git_exists=false + REM Check that git exists and get the revision. + WHERE git >NUL 2>&1 + IF "%ERRORLEVEL%" NEQ "0" ( + REM Could not find git. Exit without /B to avoid retrying. + ECHO Error: Unable to find git in your PATH. && EXIT 1 + ) 2>NUL ( - PUSHD "%flutter_root%" - FOR /f %%r IN ('git rev-parse HEAD') DO ( - SET git_exists=true + REM 'FOR /f' spawns a new terminal instance to run the command. If an + REM 'AutoRun' command is defined in the user's registry, that command could + REM change the working directory, and then we wouldn't be in the directory + REM we expect to be in. To prevent this, we need to 'PUSHD %FLUTTER_ROOT%' + REM before getting the git revision. + REM + REM See https://github.com/flutter/flutter/issues/159018 + FOR /f %%r IN ('PUSHD %FLUTTER_ROOT% ^& $git rev-parse HEAD') DO ( SET revision=%%r ) - POPD ) - REM If git didn't execute we don't have git. Exit without /B to avoid retrying. - if %git_exists% == false echo Error: Unable to find git in your PATH. && EXIT 1 SET compilekey="%revision%:%FLUTTER_TOOL_ARGS%" REM Invalidate cache if: