Skip to content

The agent that grows with you

fix(update): verify stale branch repair against its immediate tip

funky-xamarin495ab057f1a3
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 4b2100aec05..74948cf51e6 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -863,6 +863,12 @@ def _pull_updates(
# A release update moves the tree to its tag, not the branch tip: the marker names what git writes.
merge_ref = target_ref if target_ref is not None else f"origin/{branch}"
target_sha = (_git_run(git_cmd, ["rev-parse", f"{merge_ref}^{{commit}}"]).stdout or "").strip()
+ movement_baseline = pre_sync_sha or pre_pull_sha
+ if rollback_branch is not None and pre_sync_sha == target_sha:
+ # The caller already ran the target, but its local update branch was
+ # stale. Verify the fast-forward from that branch's tip, not a round
+ # trip back to the original detached SHA. Rollback still uses the latter.
+ movement_baseline = pre_pull_sha
with _best_effort('Could not write the interrupted-pull marker: %s'):
pull_marker.write_text(
f"pid={os.getpid()}\npre={pre_pull_sha}\ntarget={target_sha}\nstash={auto_stash_ref or ''}\n",
@@ -888,13 +894,13 @@ def _pull_updates(
# Do not let a second mutation hide a failed origin merge or move an
# unexpected branch. Keep local edits parked through the final check.
_verify_head_after_pull(
- git_cmd, branch, pre_sync_sha or pre_pull_sha, in_place_update=in_place_update,
+ git_cmd, branch, movement_baseline, in_place_update=in_place_update,
_windows_gateway_resume=_windows_gateway_resume)
_m()._sync_with_upstream_if_needed(
git_cmd, _m().PROJECT_ROOT, assume_yes=assume_yes, input_fn=gw_input_fn)
# Refuse an unexpected branch before syntax rollback can reset its ref.
_verify_head_after_pull(
- git_cmd, branch, pre_sync_sha or pre_pull_sha, in_place_update=in_place_update,
+ git_cmd, branch, movement_baseline, in_place_update=in_place_update,
_windows_gateway_resume=_windows_gateway_resume)
_rollback_if_pulled_syntax_error(
git_cmd, pre_sync_sha or pre_pull_sha,
diff --git a/tests/hermes_cli/test_update_existing_branch_baseline.py b/tests/hermes_cli/test_update_existing_branch_baseline.py
index 08beaff61f0..a423c8e734d 100644
--- a/tests/hermes_cli/test_update_existing_branch_baseline.py
+++ b/tests/hermes_cli/test_update_existing_branch_baseline.py
@@ -103,6 +103,20 @@ def test_locally_ahead_switch_still_needs_completion(checkout):
assert git(root, "rev-parse", "HEAD") == tip
+def test_stale_local_main_can_catch_up_to_original_detached_tip(checkout):
+ root, old, tip = checkout
+ git(root, "branch", "-f", "main", old)
+ git(root, "checkout", "-q", "--detach", tip)
+ plan = prepare(root)
+ assert plan.commit_count != 0
+ update_cmd._pull_updates(
+ ["git"], "main", plan.auto_stash_ref, prompt_for_restore=False,
+ gw_input_fn=None, discard_local_changes=False, keep_stash=False,
+ pre_sync_sha=plan.pre_sync_sha, rollback_branch=plan.rollback_branch,
+ )
+ assert git(root, "rev-parse", "main") == tip
+
+
def test_command_hands_off_after_existing_main_switch(update_tree, monkeypatch, capsys):
t = update_tree
monkeypatch.setattr("hermes_cli.update_owning_install.retarget_to_owning_install", lambda *_: None)