Skip to content

The agent that grows with you

fix(update): a failed fork sync re-owes the restart for the pulled commit (review F23)

Tekniumf0752538840c
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index 3a6ffa24766..16550fcc037 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -425,8 +425,12 @@ def _sync_with_upstream_if_needed(git_cmd: list[str], cwd: Path, *, assume_yes:
run_git(git_cmd, ["merge", "--ff-only", upstream], cwd=cwd, check=True, **_no_prompt_git_kwargs())
except subprocess.CalledProcessError as exc:
if refused or _commit.settle_failed_tree_move(cwd):
- # Back at ``pre``; that is still new code when the origin pull moved first, and
- # disarm refuses then (it only hands obligations back at the run's start commit).
+ # Back at ``pre``; that is still new code when the origin pull moved first: owe the
+ # restart for it again, not for ``target`` (disarm refuses then: it only hands
+ # obligations back at the run's start commit).
+ if pre and _git_stdout(git_cmd, ["rev-parse", "HEAD"], cwd) == pre:
+ with suppress(OSError):
+ _commit.arm_commit_obligations(cwd, pre)
_commit.disarm_commit_obligations()
print(" ✗ Failed to pull from upstream. You may need to resolve conflicts manually.")
if exc.stderr:
diff --git a/tests/hermes_cli/test_update_fork_sync_identity.py b/tests/hermes_cli/test_update_fork_sync_identity.py
index 68f57f363ae..180cb00a2ef 100644
--- a/tests/hermes_cli/test_update_fork_sync_identity.py
+++ b/tests/hermes_cli/test_update_fork_sync_identity.py
@@ -109,3 +109,32 @@ def test_an_upstream_sync_whose_marker_cannot_be_written_never_moves_the_tree(tm
update_cmd_commit.reset_for_tests()
assert _git(clone, "rev-parse", "HEAD") == commits[1]
assert _git(clone, "status", "--porcelain", "--untracked-files=no") == ""
+
+
+def test_a_failed_upstream_sync_after_the_pull_owes_the_restart_for_the_pulled_commit(tmp_path, monkeypatch):
+ """The origin pull moved c0 -> c1 and the fork ff to c2 failed back to c1: the obligation must name
+ c1 (dischargeable at HEAD), not the c2 the checkout never reached (F23)."""
+ from hermes_cli import update_cmd_commit, update_custody
+ from hermes_cli.update_host_obligation import read_host_obligation
+
+ clone, commits = _fork_behind_upstream(tmp_path, monkeypatch)
+ update_cmd_commit.reset_for_tests()
+ _git(clone, "reset", "-q", "--hard", commits[0])
+ update_cmd_commit.record_run_start(["git"], clone)
+ update_cmd_commit.arm_commit_obligations(clone, commits[1])
+ _git(clone, "reset", "-q", "--hard", commits[1]) # the committed origin pull
+ real = update_custody.run_git
+
+ def merge_fails(git_cmd, args, *rest, **kw):
+ if args[:1] == ["merge"]:
+ raise subprocess.CalledProcessError(128, args, stderr="fatal: Unable to create index.lock")
+ return real(git_cmd, args, *rest, **kw)
+
+ monkeypatch.setattr(update_custody, "run_git", merge_fails)
+ try:
+ assert _sync_with_upstream_if_needed(["git"], clone, assume_yes=True) is False
+ assert update_cmd_commit.commit_obligations_armed()
+ finally:
+ update_cmd_commit.reset_for_tests()
+ assert _git(clone, "rev-parse", "HEAD") == commits[1]
+ assert (read_host_obligation() or {}).get("expected_sha") == commits[1]