fix(terminal): force Git for Windows bash + convert native CWD for bash cd - #56384
Merged
Conversation
On Windows machines with both Linux and Git for Windows installed,
_find_bash() called shutil.which('bash') before checking known
Git-for-Windows install paths. shutil.which() may return a
non-MSYS bash which does not understand Windows-style paths.
This caused all terminal commands to fail with exit code 126
because the cwd prefix (a Windows path) was rejected.
Reorder the search: check Git for Windows install locations
(ProgramFiles/Git/bin/bash.exe etc.) before falling back to
PATH lookup. This matches the intent of the surrounding code
(portable Git preferred, system Git preferred, then PATH as
last resort).
Related: #23846 (same file, same class of Windows path issues)
…onversion The Windows _quote_cwd_for_cd override only reached _wrap_command; the snapshot bootstrap cd in init_session still used a bare shlex.quote(), so on Windows the bootstrap cd failed and pwd -P captured the login shell's dir instead of terminal.cwd. Route it through _quote_cwd_for_cd too, and add -- for hyphen-safety to match _wrap_command.
This was referenced Jul 1, 2026
This was referenced Jul 14, 2026
This was referenced Aug 3, 2026
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.
Summary
Windows terminal commands launched from PowerShell/cmd now work instead of failing with exit 126 — fixed at the root by forcing one canonical bash, not by translating around whichever shell PATH happened to resolve.
Root cause was two-layered:
_find_bash()calledshutil.which("bash")before checking Git-for-Windows install paths. On any machine with WSL installed, PATH returnsC:\Windows\System32\bash.exe(the WSL shim), so Hermes silently ran WSL bash instead of Git Bash — a different drive-mount dialect (/mnt/cvs/c).C:\Users\x) was embedded verbatim into bashcd, which no bash dialect can resolve →cd: C:\Users\...: No such file or directory→exit 126on the first command of every session.Changes
tools/environments/local.py(@Icather): reorder_find_bash()so explicit Git-for-Windows paths win overshutil.which("bash"). Git Bash always beats the WSL shim → one canonical MSYS shell, one path dialect. Fixes [Bug]: _find_bash() resolves to WSL bash before checking system Git-for-Windows paths on Native Windows #47837.tools/environments/local.py(@LeonSGP43): add_windows_to_msys_path()(C:\Users\x→/c/Users/x) + aLocalEnvironment._quote_cwd_for_cdoverride that applies it. No-op on non-Windows.tools/environments/base.py(follow-up): route theinit_sessionsnapshot bootstrapcdthrough_quote_cwd_for_cdtoo — the override previously only reached_wrap_command, so the bootstrapcdstill leaked the raw Windows path andpwd -Pcaptured the login shell's dir instead ofterminal.cwd. Also add--for hyphen-safety to match_wrap_command._windows_to_msys_path, the_wrap_commandcd conversion, and theinit_sessionbootstrap conversion.Why force one shell instead of dialect-detecting
Several competing PRs proposed detecting whether the resolved bash is Git Bash or WSL and emitting
/c/vs/mnt/c/accordingly. That translates around the symptom. The design intent (_find_bash's own error: "requires Git for Windows") is one canonical shell. Fixing the resolution order makes the whole/mnt/cdialect-mismatch bug class impossible rather than handling it downstream.Validation
_find_bash()w/ WSL on PATH + Git for Windowscdin_wrap_commandon Windowscd C:\Users\x→ exit 126cd -- /c/Users/x✓cdininit_sessionbootstrapcd C:\Users\x(fails silently)cd -- /c/Users/x✓E2E tested with real imports against a simulated Windows env (fake Git-for-Windows + WSL shim on PATH); both layers verified. Targeted suite: 17/17 green.
Supersedes #50596, #42105 (same MSYS conversion, less complete), #53475 (wrong premise — WSL is not always the shell), #54321 (dialect detection unnecessary once the shell is forced; also bundled an unrelated coding_context change), #13397 (mistitled — never converted paths), #47920 (duplicate of the
_find_bashreorder).Fixes #50594, #35459, #47837.
Infographic