diff --git a/tests/tools/test_local_env_windows_msys.py b/tests/tools/test_local_env_windows_msys.py index 09bd09e27..59f01ac56 100644 --- a/tests/tools/test_local_env_windows_msys.py +++ b/tests/tools/test_local_env_windows_msys.py @@ -260,6 +260,23 @@ class TestWindowsMsysPathconvDefaults: run_env = _make_run_env({"MSYS_NO_PATHCONV": "0"}) assert run_env.get("MSYS_NO_PATHCONV") == "0" + def test_msys2_arg_conv_excl_set_on_windows(self, monkeypatch): + # MSYS2-proper / Cygwin bash ignore MSYS_NO_PATHCONV; they honor + # MSYS2_ARG_CONV_EXCL. Both must be set on every env builder. + monkeypatch.setattr(local_mod, "_IS_WINDOWS", True) + assert _make_run_env({}).get("MSYS2_ARG_CONV_EXCL") == "*" + assert _sanitize_subprocess_env({}).get("MSYS2_ARG_CONV_EXCL") == "*" + assert hermes_subprocess_env().get("MSYS2_ARG_CONV_EXCL") == "*" + + def test_msys2_arg_conv_excl_not_set_on_posix(self, monkeypatch): + monkeypatch.setattr(local_mod, "_IS_WINDOWS", False) + assert "MSYS2_ARG_CONV_EXCL" not in _make_run_env({}) + + def test_msys2_arg_conv_excl_respects_user_override(self, monkeypatch): + monkeypatch.setattr(local_mod, "_IS_WINDOWS", True) + run_env = _make_run_env({"MSYS2_ARG_CONV_EXCL": "/custom"}) + assert run_env.get("MSYS2_ARG_CONV_EXCL") == "/custom" + # --------------------------------------------------------------------------- # Command wrapping — native Windows cwd must be Git Bash-friendly for cd diff --git a/tools/environments/local.py b/tools/environments/local.py index a3908e3d6..191ff4d4b 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -759,10 +759,18 @@ def _apply_windows_msys_bash_env_defaults(env: dict) -> None: runs terminal commands through bash on Windows, so set the standard MSYS opt-out by default. Users who need conversion can override in their env. Refs #56700. + + ``MSYS_NO_PATHCONV`` is honored by Git for Windows bash only. MSYS2-proper + and Cygwin bash (which ``_find_bash`` can still return via the final + ``shutil.which`` fallback) ignore it and honor ``MSYS2_ARG_CONV_EXCL`` + instead, so set both. ``*`` disables all argv conversion — the semantic + equivalent of ``MSYS_NO_PATHCONV=1``. Also fixes ``cmd /c`` mangling + (#56147). """ if not _IS_WINDOWS: return env.setdefault("MSYS_NO_PATHCONV", "1") + env.setdefault("MSYS2_ARG_CONV_EXCL", "*") def _path_env_key(run_env: dict) -> str | None: