Skip to content

Commit bc4fc5f

Browse files
bkonyiandrewkolos
andauthored
[ 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 flutter/flutter#159018 --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
1 parent 1e1b527 commit bc4fc5f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

bin/internal/shared.bat

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,24 @@ GOTO :after_subroutine
5252
CALL "%bootstrap_path%"
5353
)
5454

55-
REM Check that git exists and get the revision
56-
SET git_exists=false
55+
REM Check that git exists and get the revision.
56+
WHERE git >NUL 2>&1
57+
IF "%ERRORLEVEL%" NEQ "0" (
58+
REM Could not find git. Exit without /B to avoid retrying.
59+
ECHO Error: Unable to find git in your PATH. && EXIT 1
60+
)
5761
2>NUL (
58-
PUSHD "%flutter_root%"
59-
FOR /f %%r IN ('git rev-parse HEAD') DO (
60-
SET git_exists=true
62+
REM 'FOR /f' spawns a new terminal instance to run the command. If an
63+
REM 'AutoRun' command is defined in the user's registry, that command could
64+
REM change the working directory, and then we wouldn't be in the directory
65+
REM we expect to be in. To prevent this, we need to 'PUSHD %FLUTTER_ROOT%'
66+
REM before getting the git revision.
67+
REM
68+
REM See https://github.com/flutter/flutter/issues/159018
69+
FOR /f %%r IN ('PUSHD %FLUTTER_ROOT% ^& $git rev-parse HEAD') DO (
6170
SET revision=%%r
6271
)
63-
POPD
6472
)
65-
REM If git didn't execute we don't have git. Exit without /B to avoid retrying.
66-
if %git_exists% == false echo Error: Unable to find git in your PATH. && EXIT 1
6773
SET compilekey="%revision%:%FLUTTER_TOOL_ARGS%"
6874

6975
REM Invalidate cache if:

0 commit comments

Comments
 (0)