The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): conversion covers the checked-out history and starts no repack
Teknium0b570cb34c0e
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.pyindex 2161ee79022..a53ec92c839 100644--- a/hermes_cli/gitlock.py+++ b/hermes_cli/gitlock.py@@ -615,19 +615,30 @@ def convert_treeless_checkout(repo_root: Path, **run_kwargs) -> bool:A treeless checkout holds no trees, and git asks for a missing tree without telling the serverwhich ones it already has, so every checkout and path-filtered history walk downloads completedirectory snapshots again: hundreds of GB on some installs. One ``--refetch`` of the clone's- own refspec brings every commit and tree (about 120 MB for this repo); file contents stay on- demand. A- failed refetch leaves the checkout treeless, so the next update retries. Returns whether it- converted; fetch failures raise subprocess errors.+ refspec and its tags brings every commit and tree (about 120 MB for this repo); file contents+ stay on demand. The checked-out commit can sit outside both (a branch fetched by hand, a+ release ref the refspec does not name), so its history is checked offline and refetched by+ commit when trees are still missing. The new filter is recorded only once that history is+ whole: a failed or partial conversion leaves the checkout treeless, so the next update+ retries. Returns whether it converted; fetch failures raise subprocess errors."""run_kwargs["creationflags"] = run_kwargs.get("creationflags", 0) | windows_hide_flags()if _partial_clone_filter(repo_root, **run_kwargs) != "tree:0":return False- subprocess.run(- ["git", "fetch", "--quiet", "--refetch", "--filter=blob:none", "--no-tags", "origin"],- cwd=str(repo_root), check=True, capture_output=True, text=True,- encoding="utf-8", errors="replace", timeout=900, **run_kwargs,- )+ # A fetch spawns a detached gc/maintenance that would repack the whole refetch outside the+ # update's time limit; the per-command keys leave the user's own settings alone.+ refetch = ["git", "-c", "gc.auto=0", "-c", "maintenance.auto=false", "fetch", "--quiet", "--refetch",+ "--filter=blob:none", "origin"]+ fetch_kwargs = dict(cwd=str(repo_root), check=True, capture_output=True, text=True,+ encoding="utf-8", errors="replace", timeout=900, **run_kwargs)+ subprocess.run([*refetch, "--tags"], **fetch_kwargs)+ if not _history_trees_complete(repo_root, **run_kwargs):+ head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=str(repo_root), check=True,+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=30,+ **run_kwargs).stdout.strip()+ subprocess.run([*refetch, head], **fetch_kwargs)+ if not _history_trees_complete(repo_root, **run_kwargs):+ raise subprocess.CalledProcessError(1, refetch, stderr="the checked-out history is still missing trees")# A refetch into an existing partial clone leaves its configured filter alone; record the# new one only now, so a failed or interrupted refetch is retried by the next update.subprocess.run(@@ -637,6 +648,17 @@ def convert_treeless_checkout(repo_root: Path, **run_kwargs) -> bool:return True+def _history_trees_complete(repo_root: Path, **run_kwargs) -> bool:+ """Whether every tree in HEAD's history is local, checked without fetching (~3 s for this repo)."""+ env = dict(run_kwargs.pop("env", None) or noninteractive_git_env(), GIT_NO_LAZY_FETCH="1")+ walk = subprocess.run(+ ["git", "rev-list", "--objects", "--filter=blob:none", "--missing=print", "HEAD"],+ cwd=str(repo_root), capture_output=True, text=True, encoding="utf-8", errors="replace",+ timeout=300, env=env, **run_kwargs,+ )+ return walk.returncode == 0 and not any(line.startswith("?") for line in walk.stdout.splitlines())++def settle_partial_clone_maintenance(repo_root: Path) -> None:"""Persist the commit-graph-off keys on a partial clone; a full clone keeps stock maintenance.diff --git a/tests/hermes_cli/test_update_shallow_heal.py b/tests/hermes_cli/test_update_shallow_heal.pyindex 493a4f44b18..3fe5b69d6bc 100644--- a/tests/hermes_cli/test_update_shallow_heal.py+++ b/tests/hermes_cli/test_update_shallow_heal.py@@ -66,10 +66,45 @@ def test_depth_prefetch_on_a_full_clone_restores_ancestry_and_keeps_it_full(tmp_assert _git(clone, "config", "--get", "remote.origin.promisor").returncode != 0-def test_treeless_checkout_gets_every_tree_once_so_history_walks_stay_offline(tmp_path):+def _side_history(origin: Path, ref: str) -> None:+ """Three commits off main~1 that only ``ref`` reaches; main's branch is left where it was."""+ _git(origin, "checkout", "-q", "-b", "side", "main~1")+ for i in range(3):+ (origin / "f.txt").write_text(f"side {i}\n", encoding="utf-8")+ _git(origin, "commit", "-qam", f"s{i}")+ if ref.startswith("refs/tags/"):+ _git(origin, "tag", ref.removeprefix("refs/tags/"))+ _git(origin, "checkout", "-q", "main")+ if ref.startswith("refs/tags/"):+ _git(origin, "branch", "-D", "side")+++def _check_out_main(clone: Path) -> None:+ pass+++def _check_out_tag_only_release(clone: Path) -> None:+ _git(clone, "fetch", "-q", "origin", "refs/tags/v9:refs/tags/v9")+ _git(clone, "checkout", "-q", "--detach", "v9")+++def _check_out_branch_outside_the_refspec(clone: Path) -> None:+ _git(clone, "config", "remote.origin.fetch", "+refs/heads/main:refs/remotes/origin/main")+ _git(clone, "fetch", "-q", "origin", "side:side")+ _git(clone, "checkout", "-q", "side")++[email protected]("ref, check_out, history", [+ ("refs/heads/side", _check_out_main, 5),+ ("refs/tags/v9", _check_out_tag_only_release, 7),+ ("refs/heads/side", _check_out_branch_outside_the_refspec, 7),+])+def test_treeless_checkout_gets_its_whole_history_once_so_walks_stay_offline(tmp_path, ref, check_out, history):origin = _origin(tmp_path, 5)+ _side_history(origin, ref)clone = tmp_path / "clone"- _git(tmp_path, "clone", "-q", "--filter=tree:0", f"file://{origin}", str(clone))+ _git(tmp_path, "clone", "-q", "--filter=tree:0", "--no-tags", f"file://{origin}", str(clone))+ check_out(clone)offline = dict(os.environ, GIT_NO_LAZY_FETCH="1")walk = ["git", "log", "--format=%H", "--", "f.txt"]assert subprocess.run(walk, cwd=clone, env=offline, capture_output=True).returncode != 0@@ -77,8 +112,8 @@ def test_treeless_checkout_gets_every_tree_once_so_history_walks_stay_offline(tmassert convert_treeless_checkout(clone) is Trueassert _git(clone, "config", "remote.origin.partialclonefilter").stdout.strip() == "blob:none"- walked = subprocess.run(walk, cwd=clone, env=offline, capture_output=True, text=True)- assert walked.returncode == 0 and len(walked.stdout.split()) == 5+ walked = subprocess.run(walk, cwd=clone, env=offline, capture_output=True, text=True, encoding="utf-8")+ assert walked.returncode == 0 and len(walked.stdout.split()) == historyassert convert_treeless_checkout(clone) is False