Skip to content

The agent that grows with you

fix(update): the parked-branch check skips git cherry on a partial clone

Teknium86bdb75b2bbe
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index 0e145fae7c3..ee7453aa0e0 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -201,6 +201,12 @@ def _assess_parked_branch_switch(git_cmd: list[str], cwd: Path, current_branch:
ahead_count = int(ahead.stdout.strip())
if ahead_count == 0:
return True, ""
+ # Git before 2.44 ignores GIT_NO_LAZY_FETCH, so on a partial clone cherry still lazy-fetches
+ # without bound (git 2.43 on WSL hung here, #124767). Its patch-ids need blobs a partial clone
+ # keeps on the remote, so it rarely refines anything there: settle for the commit count.
+ promisor = _git_run(git_cmd, ["config", "--get-regexp", r"^(remote\..*\.promisor|extensions\.partialclone)$"], cwd)
+ if any(line.split()[-1].lower() != "false" for line in promisor.stdout.splitlines()):
+ return True, f"unmerged:{ahead_count}"
# The patch-id refinement must never fetch: on a tree:0 clone `git cherry` lazy-fetches
# a tree batch per commit and, with nothing bounding it, one such walk wrote 332 packs /
# 180 GiB over 7 h on Windows (#131444). With lazy fetch off a missing object fails the
diff --git a/tests/hermes_cli/test_update_parked_branch_guard.py b/tests/hermes_cli/test_update_parked_branch_guard.py
index 1b14dac2237..bcc0c333857 100644
--- a/tests/hermes_cli/test_update_parked_branch_guard.py
+++ b/tests/hermes_cli/test_update_parked_branch_guard.py
@@ -288,6 +288,28 @@ def test_parked_branch_guard_never_lazy_fetches_from_a_live_promisor(tmp_path, m
assert _pack_count(clone) == packs_before
+def test_parked_branch_guard_skips_cherry_on_a_partial_clone_when_git_ignores_no_lazy_fetch(
+ tmp_path, monkeypatch):
+ """Git before 2.44 ignores GIT_NO_LAZY_FETCH, so the no-lazy-fetch child alone would still
+ fetch without bound there (#124767, git 2.43). A partial clone must not reach cherry at all:
+ with the override emptied, as old git effectively sees it, the assessment starts no fetch."""
+ import hermes_cli.update_cmd_git as update_cmd_git
+ monkeypatch.setattr(update_cmd_git, "NO_LAZY_FETCH_ENV", {})
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", os.devnull)
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
+ clone = _treeless_repo_pair(tmp_path, promisor_reachable=True)
+ (clone / "feature.txt").write_text("unmerged work\n", encoding="utf-8")
+ _git(clone, "add", "feature.txt")
+ _git(clone, "commit", "-qm", "feature work")
+ trace = tmp_path / "trace2.json"
+ monkeypatch.setenv("GIT_TRACE2_EVENT", str(trace))
+ safe, reason = update_cmd._assess_parked_branch_switch(GIT, clone, "old-feature", "main")
+ monkeypatch.delenv("GIT_TRACE2_EVENT")
+ events = [json.loads(line) for line in trace.read_text(encoding="utf-8").splitlines()]
+ assert (safe, reason) == (True, "unmerged:1")
+ assert [e["argv"] for e in events if e.get("event") == "child_start" and "fetch" in e.get("argv", [])] == []
+
+
# ---------------------------------------------------------------------------
# Skip warning content
# ---------------------------------------------------------------------------