Skip to content

fix(terminal): force Git for Windows bash + convert native CWD for bash cd - #56384

Merged
teknium1 merged 3 commits into
mainfrom
hermes/hermes-72f92c25
Jul 1, 2026
Merged

fix(terminal): force Git for Windows bash + convert native CWD for bash cd#56384
teknium1 merged 3 commits into
mainfrom
hermes/hermes-72f92c25

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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:

  1. _find_bash() called shutil.which("bash") before checking Git-for-Windows install paths. On any machine with WSL installed, PATH returns C:\Windows\System32\bash.exe (the WSL shim), so Hermes silently ran WSL bash instead of Git Bash — a different drive-mount dialect (/mnt/c vs /c).
  2. Native cwd (C:\Users\x) was embedded verbatim into bash cd, which no bash dialect can resolve → cd: C:\Users\...: No such file or directoryexit 126 on the first command of every session.

Changes

  • tools/environments/local.py (@Icather): reorder _find_bash() so explicit Git-for-Windows paths win over shutil.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) + a LocalEnvironment._quote_cwd_for_cd override that applies it. No-op on non-Windows.
  • tools/environments/base.py (follow-up): route the init_session snapshot bootstrap cd through _quote_cwd_for_cd too — the override previously only reached _wrap_command, so the bootstrap cd still leaked the raw Windows path and pwd -P captured the login shell's dir instead of terminal.cwd. Also add -- for hyphen-safety to match _wrap_command.
  • Tests: cover _windows_to_msys_path, the _wrap_command cd conversion, and the init_session bootstrap 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/c dialect-mismatch bug class impossible rather than handling it downstream.

Validation

Before After
_find_bash() w/ WSL on PATH + Git for Windows returns WSL shim returns Git for Windows bash
cd in _wrap_command on Windows cd C:\Users\x → exit 126 cd -- /c/Users/x
cd in init_session bootstrap cd C:\Users\x (fails silently) cd -- /c/Users/x
Non-Windows unchanged unchanged (no-op)

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_bash reorder).

Fixes #50594, #35459, #47837.

Infographic

infographic

Icather and others added 3 commits July 1, 2026 05:21
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.
@teknium1
teknium1 merged commit 5d613a5 into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-72f92c25 branch July 1, 2026 12:35
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management backend/local Local shell execution platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows labels Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

4 participants