Skip to content

The agent that grows with you

fix(update): the fork sync's marker target and deferred push check use the counted commit (m2)

Teknium131927f4516d
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index 961e6e9cd39..a15eb82e41b 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -413,7 +413,7 @@ def _sync_with_upstream_if_needed(git_cmd: list[str], cwd: Path, *, assume_yes:
from hermes_cli import update_cmd_commit as _commit
from hermes_cli._early_recovery import interrupted_pull_marker
pre = _git_stdout(git_cmd, ["rev-parse", "HEAD"], cwd)
- target = _git_stdout(git_cmd, ["rev-parse", "upstream/main^{commit}"], cwd) or ""
+ target = upstream # the counted commit is the marker's target and the merge's (m2)
_commit.arm_commit_obligations(cwd, target)
with suppress(OSError):
_commit.arm_tree_move(git_cmd, cwd, pre=pre, target=target, stash=None)
@@ -443,8 +443,9 @@ def _push_synced_fork(git_cmd: list[str], cwd: Path) -> None:
(or an earlier one whose push failed) fast-forwarded main from upstream.
"""
head = _git_stdout(git_cmd, ["rev-parse", "HEAD"], cwd)
- upstream = _git_stdout(git_cmd, ["rev-parse", "-q", "--verify", "upstream/main^{commit}"], cwd)
- origin = _git_stdout(git_cmd, ["rev-parse", "-q", "--verify", "origin/main^{commit}"], cwd)
+ # Full ref names: a local branch called upstream/main or origin/main must not answer (m2).
+ upstream = _git_stdout(git_cmd, ["rev-parse", "-q", "--verify", "refs/remotes/upstream/main^{commit}"], cwd)
+ origin = _git_stdout(git_cmd, ["rev-parse", "-q", "--verify", "refs/remotes/origin/main^{commit}"], cwd)
if not head or head != upstream or head == origin:
return
if origin and not _git_ok(git_cmd, ["merge-base", "--is-ancestor", origin, head], cwd):
diff --git a/tests/hermes_cli/test_update_fork_sync_identity.py b/tests/hermes_cli/test_update_fork_sync_identity.py
index fcb6c1418e0..f090d05a110 100644
--- a/tests/hermes_cli/test_update_fork_sync_identity.py
+++ b/tests/hermes_cli/test_update_fork_sync_identity.py
@@ -50,7 +50,23 @@ def test_a_local_branch_named_upstream_main_never_changes_what_the_sync_counts_o
_git(clone, "fetch", "-q", "upstream")
_git(clone, "branch", "upstream/main", commits[1])
+ from hermes_cli import update_cmd_commit
+ from hermes_cli.update_cmd_git import _push_synced_fork
+
+ real_arm = update_cmd_commit.arm_tree_move
+ armed = []
+
+ def arm(*args, **kwargs):
+ armed.append(kwargs["target"])
+ return real_arm(*args, **kwargs)
+
+ monkeypatch.setattr(update_cmd_commit, "arm_tree_move", arm)
assert _sync_with_upstream_if_needed(["git"], clone, assume_yes=True) is True
out = capsys.readouterr().out
assert "Fork is 2 commit(s) behind upstream" in out, out
assert _git(clone, "rev-parse", "HEAD") == commits[2]
+ # The tree-move marker names the merged commit: a killed merge is repaired toward it.
+ assert armed == [commits[2]]
+ # The deferred fork push checks HEAD against the same remote-tracking commit, not the shadow.
+ _push_synced_fork(["git"], clone)
+ assert _git(origin, "rev-parse", "refs/heads/main") == commits[2]