Skip to content

The agent that grows with you

fix: Desktop update check finds the git a Windows install ships with

Teknium6addc2f7dc6d
diff --git a/hermes_cli/source_check.py b/hermes_cli/source_check.py
index c80a4970c0a..3eae1ecefcc 100644
--- a/hermes_cli/source_check.py
+++ b/hermes_cli/source_check.py
@@ -7,6 +7,7 @@ from __future__ import annotations
import json
import logging
import os
+import shutil
import subprocess
import time
from dataclasses import dataclass
@@ -227,6 +228,21 @@ def _unsupported_reason(stamp: dict, root: Path, *, explicit_root: bool, embedde
return None
+def _installed_git(git: str) -> str:
+ """``git`` as given, unless it is a bare ``git`` PATH lacks: then the git ``hermes update`` runs.
+
+ A Windows source install's only git is often the copy install.ps1 staged in PM's store, which
+ is on PATH only inside ``hermes update`` (``expose_pm_git``). Desktop and the dashboard pass a
+ bare ``git`` there, it dies with WinError 2, and the check reports ``head-unavailable``, which
+ Desktop shows as "couldn't reach the update server" while ``hermes update`` works.
+ """
+ if git != "git" or shutil.which(git):
+ return git
+ from hermes_cli.update_pause_record import _git_executable
+
+ return _git_executable()
+
+
def _read_checkout(root: Path, git: str, embedded: Optional[str]) -> _Checkout:
# An embedded revision has no checkout to ask: it always tracks the official repository.
head = embedded or _git_stdout(["rev-parse", "HEAD"], cwd=root, git=git)
@@ -411,7 +427,7 @@ def check_for_updates(*, install_root: Path | None = None, home: Path | None = N
return {**result, "reason": "disabled"}
channel = resolve_update_channel(config, root) if channel is None else validate_name(channel)
forward_only = rides_default_channel(channel_record(config, root), channel, root)
- co = _read_checkout(root, git, embedded)
+ co = _read_checkout(root, _installed_git(git), embedded)
desktop_config = _read_json(branch_config_path) if branch_config_path else None
configured_branch = _configured_branch(desktop_config)
selected_branch = branch or configured_branch or _checked_out_branch(co.current_branch, "main")
diff --git a/tests/hermes_cli/test_source_check.py b/tests/hermes_cli/test_source_check.py
index 7d20412da7f..d1f3c6abcbd 100644
--- a/tests/hermes_cli/test_source_check.py
+++ b/tests/hermes_cli/test_source_check.py
@@ -142,6 +142,27 @@ def test_target_worktree_owns_admission_and_fork_comparison(installation, monkey
assert {str(p.relative_to(root)): p.read_bytes() for p in (root / ".git").rglob("*") if p.is_file()} == before
+def test_bare_git_off_path_reads_through_the_updaters_git(installation, monkeypatch, tmp_path):
+ """Desktop passes a bare ``git`` when it found none; a Windows install's only git is PM's
+ store copy, off PATH outside ``hermes update``. The check must read HEAD through that git."""
+ import shutil
+
+ from hermes_cli import update_pause_record
+ from hermes_cli.source_check import check_for_updates
+
+ root, _linked, home, _base, head, responses, _requests, _git = installation
+ responses["/repos/fixture/fork/commits/main"] = (200, head)
+ store_git = shutil.which("git")
+ empty = tmp_path / "no-git-on-path"
+ empty.mkdir()
+ monkeypatch.setenv("PATH", str(empty))
+ monkeypatch.setattr(update_pause_record, "_git_executable", lambda: store_git)
+ status = check_for_updates(install_root=root, home=home, git="git", force=True)
+ assert status.get("error") is None, status
+ assert status["currentSha"] == head
+ assert status["behind"] == 0
+
+
@pytest.mark.parametrize("tip_kind,compare,expected", [
("head", None, 0), ("base", None, 0),
("unknown", {"ahead_by": 61}, 61), ("unknown", {"ahead_by": 0}, 0),