From ad5f3341d385ae2448cebd4a455fd01a322f8cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=B6=8A=E7=BE=BD=E6=AF=9B?= <97326386+Icather@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:24:17 +0800 Subject: [PATCH] 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) --- tools/environments/local.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/environments/local.py b/tools/environments/local.py index 49c87cd08..528fd5329 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -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"