fix(terminal): prefer Git for Windows bash over Linux bash on Windows

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)
This commit is contained in:
灵越羽毛 2026-06-15 18:24:17 +08:00 committed by Teknium
parent ba0bc01d1f
commit ad5f3341d3

View file

@ -509,10 +509,10 @@ def _find_bash() -> str:
if os.path.isfile(candidate):
return candidate
found = shutil.which("bash")
if found:
return found
# Check known Git for Windows install locations before PATH lookup.
# On machines with both WSL and Git for Windows, shutil.which("bash")
# may return WSL's bash (which doesn't understand Windows paths and
# will fail silently). Explicit Git-for-Windows paths avoid that.
for candidate in (
os.path.join(os.environ.get("ProgramFiles", r"C:\Program Files"), "Git", "bin", "bash.exe"),
os.path.join(os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)"), "Git", "bin", "bash.exe"),
@ -521,6 +521,10 @@ def _find_bash() -> str:
if candidate and os.path.isfile(candidate):
return candidate
found = shutil.which("bash")
if found:
return found
raise RuntimeError(
"Git Bash not found. Hermes Agent requires Git for Windows on Windows.\n"
"Install it from: https://git-scm.com/download/win\n"