Skip to content

The agent that grows with you

fix(updater): fetch branches by explicit refspec so narrow clones resolve the compare ref

Yuan Liab6cc2fd84c7
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index d5dc9530526..9481de8a975 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1384,7 +1384,11 @@ def _cmd_update_impl(args, gateway_mode: bool):
if release_sha:
fetch_result = _git_run(git_cmd, ["fetch", "--no-tags", "origin", target_ref], network=True)
else:
- fetch_result = _git_run(git_cmd, ["fetch", "origin", branch], network=True)
+ # Explicit refspec so the tracking ref lands even on narrow clones whose only
+ # configured refspec is a tag (#125112): a branch-name fetch would leave the
+ # target unresolvable and the checkout/compare below would fail.
+ fetch_result = _git_run(
+ git_cmd, ["fetch", "origin", f"+refs/heads/{branch}:refs/remotes/origin/{branch}"], network=True)
if fetch_result.returncode != 0:
_print_fetch_failure(fetch_result.stderr)
_m()._resume_windows_gateways_after_update(_windows_gateway_resume)
diff --git a/hermes_cli/update_cmd_check.py b/hermes_cli/update_cmd_check.py
index c3e75f27222..0ee7fe83356 100644
--- a/hermes_cli/update_cmd_check.py
+++ b/hermes_cli/update_cmd_check.py
@@ -73,7 +73,11 @@ def is_shallow_repository(git_cmd: list[str], root: Path) -> bool:
def _fetch(git_cmd: list[str], root: Path, depth_args: list[str], remote: str, branch: str):
print(f"→ Fetching from {remote}...")
- return _git(git_cmd, root, ["fetch", *depth_args, remote, branch], **_uc()._no_prompt_git_kwargs())
+ # Fetch by explicit refspec: on narrow clones (tag-pinned --single-branch, #125112) the
+ # configured remote.<remote>.fetch maps only the tag, so a branch-name fetch writes
+ # FETCH_HEAD and never creates the tracking ref the compare step resolves.
+ refspec = f"+refs/heads/{branch}:refs/remotes/{remote}/{branch}"
+ return _git(git_cmd, root, ["fetch", *depth_args, remote, refspec], **_uc()._no_prompt_git_kwargs())
def fetch_compare_branch(git_cmd: list[str], root: Path, branch: str, depth_args: list[str]):
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index f9fa9a34bc0..59dac5e9c47 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -341,7 +341,9 @@ def _sync_with_upstream_if_needed(git_cmd: list[str], cwd: Path, *, assume_yes:
return False
print("\n→ Fetching upstream...")
try:
- subprocess.run(git_cmd + ["fetch", "upstream", "main", "--quiet"], cwd=cwd, capture_output=True, check=True, **_no_prompt_git_kwargs())
+ # Explicit refspec (#125112): tag-pinned narrow clones never build upstream/main
+ # from a branch-name fetch, and the comparison below resolves it.
+ subprocess.run(git_cmd + ["fetch", "upstream", "+refs/heads/main:refs/remotes/upstream/main", "--quiet"], cwd=cwd, capture_output=True, check=True, **_no_prompt_git_kwargs())
except subprocess.CalledProcessError:
print(" ✗ Failed to fetch upstream. Skipping upstream sync.")
return False