[ Tool ] Fix "Error: Unable to find git in your PATH" when Command Processor AutoRun
registry key is defined (#159424)
cmd.exe will read from the AutoRun registry key at launch and execute the commands listed in the key. Since `FOR /F IN (command) ...` causes a new terminal instance to start, the AutoRun commands will be run again, possibly changing the current working directory. In this case, the `git rev-parse HEAD` check run in `shared.bat` could fail, which we were assuming meant `git` was not on the user's PATH. This change ensures that `git rev-parse HEAD` will always run in %FLUTTER_ROOT% and explicitly adds a separate check for `git` using `WHERE git` to more accurately determine if `git` is on the PATH. Fixes https://github.com/flutter/flutter/issues/159018 --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
This commit is contained in:
parent
1e1b5271f4
commit
bc4fc5ffb9
@ -52,18 +52,24 @@ GOTO :after_subroutine
|
|||||||
CALL "%bootstrap_path%"
|
CALL "%bootstrap_path%"
|
||||||
)
|
)
|
||||||
|
|
||||||
REM Check that git exists and get the revision
|
REM Check that git exists and get the revision.
|
||||||
SET git_exists=false
|
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 (
|
2>NUL (
|
||||||
PUSHD "%flutter_root%"
|
REM 'FOR /f' spawns a new terminal instance to run the command. If an
|
||||||
FOR /f %%r IN ('git rev-parse HEAD') DO (
|
REM 'AutoRun' command is defined in the user's registry, that command could
|
||||||
SET git_exists=true
|
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
|
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%"
|
SET compilekey="%revision%:%FLUTTER_TOOL_ARGS%"
|
||||||
|
|
||||||
REM Invalidate cache if:
|
REM Invalidate cache if:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user