Repository navigation
fix(shell): discover native Git Bash on Windows instead of WSL - #243
Merged
Merged
Conversation
On Windows, a Git for Windows install in a non-default directory only puts <Git>\cmd on PATH, so shell discovery fell through to `where bash.exe` and picked C:\Windows\System32\bash.exe, silently running commands inside WSL. - Look for Git Bash in Program Files, Program Files (x86), %LOCALAPPDATA%\Programs\Git, then relative to each git.exe on PATH, then native bash.exe on PATH. Resolve symlinks and drop the where.exe dependency. - Never select the WSL launcher automatically; an explicit shellPath to it keeps its stdin command transport. - Add the Git installation's bin and usr/bin to the Git Bash child PATH only. - On Windows, pipe background command output into the log file instead of handing the file descriptor to MSYS, which exited 1 with an empty log. - Generate candidates lazily so a standard install returns without scanning PATH on every command or permission check. Fixes #136 Co-authored-by: ZXJC-niusile <2632590648@qq.com>
Config values written as `!command` were run with a direct spawnSync on the resolved shell, bypassing spawnShellChild, so on Windows they did not get the Git installation's bin and usr/bin on PATH. Export withGitBashPath and apply it there too so these commands see the same tools as run_command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #136. If Git for Windows is installed in a non-default directory, the installer only adds
<Git>\cmdto PATH. Shell discovery then falls through towhere bash.exe, which returnsC:\Windows\System32\bash.exefirst. That is the WSL launcher, so commands silently run inside WSL without the Windows Node/npm toolchain. Separately, background commands under Git Bash exit 1 with an empty log when the log file descriptor is handed to MSYS.Summary
This combines the contributor's fork PRs (ZXJC-niusile#1 and #2) with one review fix.
%LOCALAPPDATA%\Programs\Git→ Git installation next to eachgit.exeon PATH (cmd,bin,mingw32/64/bin) → nativebash.exeon PATH. Symlinks are resolved, andwhere.exeis no longer used. PowerShell lookup uses the same PATH scan.shellPathpointing at the WSL launcher still works, and still uses the stdin command transport.binandusr/binare prepended for the Git Bash child process only. The system PATH is unchanged.!commandconfig values (resolve-config-value.ts) now get the same Git Bash child PATH asrun_command.run_commandand every permission check.Compatibility
On native Windows with only WSL
bash.exeavailable, Step now fails with clear instructions instead of silently switching to the Linux toolchain. Users who want WSL can setshellPathexplicitly or run Step inside WSL.Validation
test/shell-discovery.test.ts: custom, portable and mingw Git roots; known install locations; Git shims; symlinks; quoted and relative PATH entries; WSL rejection under a customSystemRoot; explicit WSL transport; Git Bash child PATH; Unix fallbacks; no PATH scan when a known install exists. The two lazy-lookup tests fail against the previous eager version.test/step-tool-profile.test.ts: background logs capture both stdout and stderr.pnpm run checkpasses, and the shell/bash/background/powershell vitest subset passes (447 tests).test.shpassing on Ubuntu 24.04 (WSL2) for the fork changes. No Windows run yet for the lazy-lookup change.Out of scope
Two Windows baseline issues found by the contributor are not fixed here:
execFileSync("npm", ...)fails with ENOENT, and config migration extracts filenames from backslash paths incorrectly.Co-authored-by: @ZXJC-niusile