Skip to content

The agent that grows with you

fix(update): give git-less Windows installs PM's git for update and source completion

teknium1305072f4a645
diff --git a/hermes_cli/_subprocess_compat.py b/hermes_cli/_subprocess_compat.py
index d03944f654c..096995a538d 100644
--- a/hermes_cli/_subprocess_compat.py
+++ b/hermes_cli/_subprocess_compat.py
@@ -28,6 +28,7 @@ __all__ = [
"bounded_git_probe",
"bounded_probe_run",
"selected_git_env",
+ "expose_pm_git",
"noninteractive_git_env",
"NO_DRIVER_DIFF_FLAGS",
"NO_LAZY_FETCH_ENV",
@@ -371,6 +372,27 @@ def selected_git_env(base: Mapping[str, str] | None = None) -> dict[str, str]:
return env
+def expose_pm_git() -> None:
+ """Put PM's git on this process's PATH when Windows has no git of its own.
+
+ On a machine without git, install.ps1 stages the pinned Git for Windows for
+ its own process only; PM's facts never record it. Every later bare ``git``
+ (``hermes update``, the source-completion stamp) then died with
+ ``[WinError 2]``. Callers are explicit user actions (like
+ ``ensure_tools_for_sync``), so acquire PM's git outright; children inherit
+ the PATH. A machine with a working git is untouched. Raises what
+ ``pm.ensure`` raises.
+ """
+ if sys.platform != "win32" or shutil.which("git"):
+ return
+ from pm import ensure
+
+ env = ensure("git", explicit=True).env
+ path = next((value for key, value in env.items() if key.upper() == "PATH"), None)
+ if path:
+ os.environ["PATH"] = path
+
+
def noninteractive_git_env(base: "Mapping[str, str] | None" = None) -> dict[str, str]:
"""Environment for *internal* git invocations that must never prompt.
diff --git a/hermes_cli/source_completion.py b/hermes_cli/source_completion.py
index 8df1301fb72..58ec5d296a2 100644
--- a/hermes_cli/source_completion.py
+++ b/hermes_cli/source_completion.py
@@ -47,6 +47,14 @@ def complete_source_checkout(
from hermes_cli.venv_sync import publish_launchers
root = Path(root)
+ try:
+ from hermes_cli._subprocess_compat import expose_pm_git
+
+ # The builds, the release-history refresh and the install stamp all run
+ # git; a fresh Windows machine has only PM's.
+ expose_pm_git()
+ except Exception as exc: # noqa: BLE001 — git-less steps below still complete
+ print(f"⚠ Could not provide git for the source completion: {exc}", file=sys.stderr)
publish_launchers(root)
build_update_products(root, desktop=desktop)
if announce:
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index bab5db9dc0a..74d15987182 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1104,6 +1104,9 @@ def _prepare_git_command() -> tuple[bool, list, bool]:
print(" curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash")
sys.exit(1)
+ from hermes_cli._subprocess_compat import expose_pm_git
+
+ expose_pm_git()
git_cmd = _base_git_cmd()
if sys.platform == "win32" and git_dir.exists():
_git_run(git_cmd, ["config", "windows.appendAtomically", "false"])
diff --git a/tests/hermes_cli/test_update_pm_git.py b/tests/hermes_cli/test_update_pm_git.py
new file mode 100644
index 00000000000..a0f974f96ec
--- /dev/null
+++ b/tests/hermes_cli/test_update_pm_git.py
@@ -0,0 +1,40 @@
+"""Windows machines whose only git is the one PM provides (install.ps1 fresh installs)."""
+import os
+
+import pm
+import pytest
+
+from hermes_cli import _subprocess_compat as compat
+from pm.package import Runner
+
+
+def windows(monkeypatch):
+ monkeypatch.setattr(compat.sys, "platform", "win32")
+ monkeypatch.setenv("PATH", r"C:\Windows\System32")
+
+
+def test_pm_git_goes_on_path_when_windows_has_none(windows, monkeypatch):
+ calls = []
+ store_path = r"C:\store\git-2.53.0+3-win32-x64\cmd;C:\store\git-2.53.0+3-win32-x64\usr\bin;C:\Windows\System32"
+
+ def ensure(name, **kwargs):
+ calls.append((name, kwargs))
+ return Runner(name, {"Path": store_path})
+
+ monkeypatch.setattr(compat.shutil, "which", lambda name, *a, **k: None)
+ monkeypatch.setattr(pm, "ensure", ensure)
+
+ compat.expose_pm_git()
+
+ assert calls == [("git", {"explicit": True})]
+ assert os.environ["PATH"] == store_path
+
+
+def test_a_working_windows_git_is_left_alone(windows, monkeypatch):
+ monkeypatch.setattr(compat.shutil, "which", lambda name, *a, **k: r"C:\Program Files\Git\cmd\git.exe")
+ monkeypatch.setattr(pm, "ensure", lambda *a, **k: pytest.fail("acquired PM git over a working one"))
+
+ compat.expose_pm_git()
+
+ assert os.environ["PATH"] == r"C:\Windows\System32"