Skip to content

The agent that grows with you

fix(update): a rollback that cannot resume names the way back, never a reset --hard

Teknium9c58d9e65c4a
diff --git a/hermes_cli/_early_recovery.py b/hermes_cli/_early_recovery.py
index 86d623cfb2b..7d157b0e3e3 100644
--- a/hermes_cli/_early_recovery.py
+++ b/hermes_cli/_early_recovery.py
@@ -966,8 +966,13 @@ def _resume_killed_rollback(git, read_head, fields: dict[str, str], git_dir: Pat
# ``target`` since is theirs (and the update's branch would stay on the broken commit).
named = git("symbolic-ref", "-q", "HEAD")
if "ref" not in fields or (named.stdout.strip() if named.returncode == 0 else "") != fields["ref"].strip():
+ # The marker stays: switching back lets the next launch resume. Never a reset recipe (F73):
+ # a reset --hard would wipe whatever the user changed on the branch they checked out.
+ ref = fields.get("ref", "").strip().removeprefix("refs/heads/")
+ back = (f"`git -C {root} checkout {ref}`" if ref
+ else f"`git -C {root} checkout --detach {fields.get('target', '').strip()[:10] or pre[:10]}`")
print(f"⚠ An interrupted `hermes update` rollback to {pre[:10]} was not resumed: HEAD now names "
- f"another branch. Run `git reset --hard {pre[:10]}` on the updated branch to finish it.",
+ f"another branch. Switch back with {back}, then launch `hermes` again to finish it.",
file=sys.stderr)
return None
# A syntax rollback killed before it moved HEAD back: redo that step (HEAD and index, no file),
diff --git a/tests/hermes_cli/test_update_interrupted_pull.py b/tests/hermes_cli/test_update_interrupted_pull.py
index 5121212991b..97ec8f94bb5 100644
--- a/tests/hermes_cli/test_update_interrupted_pull.py
+++ b/tests/hermes_cli/test_update_interrupted_pull.py
@@ -837,3 +837,18 @@ def test_the_tree_move_marker_is_durable_before_it_appears_under_its_name(checko
assert [dst for _src, dst in replaced] == [marker]
assert f"target={b}" in marker.read_text(encoding="utf-8")
assert not list(marker.parent.glob(marker.name + "*.tmp"))
+
+
+def test_a_rollback_whose_branch_was_switched_away_never_advises_a_reset(tmp_path, capsys):
+ """The user checked out another branch after the rollback was killed: the restore must not
+ resume, and its advice must never be `git reset --hard` (F73: it wipes the user's work); it
+ names the way back so the next launch can finish (review C9)."""
+ root, pre, target = _broken_release(tmp_path, 2)
+ marker = _rollback_marker(root, pre, target)
+ _git(root, "checkout", "-q", "-b", "elsewhere")
+
+ assert er.restore_interrupted_pull(root) is False
+
+ err = capsys.readouterr().err
+ assert "was not resumed" in err and "reset --hard" not in err
+ assert "checkout main" in err and marker.exists()