Skip to content

feat(rewrite): print post-rewrite recovery instructions - #17

Merged
gfargo-horizon-agent[bot] merged 4 commits into
mainfrom
agent/git-rewrite-294-git-rewrite-7-feat-post-rewrite-recovery
Jul 4, 2026
Merged

feat(rewrite): print post-rewrite recovery instructions#17
gfargo-horizon-agent[bot] merged 4 commits into
mainfrom
agent/git-rewrite-294-git-rewrite-7-feat-post-rewrite-recovery

Conversation

@gfargo-horizon-agent

@gfargo-horizon-agent gfargo-horizon-agent Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What

After a successful (non-dry-run) history rewrite, print the pre-rewrite HEAD sha and the exact recovery command(s) needed to undo it, tailored to whichever backend actually ran.

Why

Closes #7
Plane: OSS-294

How

  • backends.rewrite() now captures git rev-parse HEAD immediately before the mutating command runs and returns a RewriteResult(backend_name, pre_rewrite_sha) instead of None.
  • cli._force_push_reminder() now takes the RewriteResult and prints:
    • Pre-rewrite HEAD : <sha> and To undo (filter-repo): git reset --hard <sha> whenever a real rewrite ran (filter-repo deletes refs/original/ by default, so this is its only recovery path).
    • An additional To undo (filter-branch): git reset --hard refs/original/<ref> line when the filter-branch backend was used (it preserves originals there), resolving the current branch via git symbolic-ref when --refs wasn't given.
  • cmd_strip, cmd_replace, and cmd_run thread the RewriteResult through to _force_push_reminder.
  • --dry-run output is unchanged — the new recovery block is only printed on a real rewrite.

Testing

  • build passes
  • tests pass / added (tests/test_backends.py, plus new recovery-output tests in tests/test_cli.py)
  • lint clean (ruff check)
  • CI: pending

🤖 Generated by the harbor agent loop. Reviewed by a human before merge.

Closes #7

Capture the pre-rewrite HEAD sha before the rewrite command runs and
surface it afterwards, along with the exact `git reset --hard` command
to undo the rewrite. When the filter-branch backend was used, also
show the refs/original/ recovery path since filter-branch (unlike
filter-repo) preserves originals there.

Closes #7

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent review (claude-sonnet-5) — LGTM

REVIEW: LGTM
RESOLVES: full

Implements exactly what the plan and issue specify: pre-rewrite HEAD sha is captured right before the mutating subprocess call, RewriteResult threads backend info through cli.py, and the filter-branch refs/original/ recovery line only appears for that backend. Dry-run output is unchanged, tests cover both backends and the dry-run no-op case, and the full suite (76 tests) plus ruff pass cleanly.

1 nit — 1 inline on the diff

Comment thread git_rewrite/cli.py

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (claude-sonnet-5, delta) — LGTM

REVIEW: LGTM
RESOLVES: full

The ref-type assumption in the filter-branch undo line is now fixed by checking whether the ref is already fully qualified before prefixing with refs/heads/, and new tests cover both filter-repo and filter-branch paths plus the dry-run no-extra-output case. No new bugs or scope creep found; only a trivial ruff-format nit (missing blank line after docstring in RewriteResult).

1 nit — 1 inline on the diff

Comment thread git_rewrite/backends.py
Co-authored-by: gfargo-horizon-agent[bot] <294710345+gfargo-horizon-agent[bot]@users.noreply.github.com>
@gfargo-horizon-agent
gfargo-horizon-agent Bot merged commit c4ecba7 into main Jul 4, 2026
3 checks passed
@gfargo-horizon-agent
gfargo-horizon-agent Bot deleted the agent/git-rewrite-294-git-rewrite-7-feat-post-rewrite-recovery branch July 4, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: post-rewrite recovery instructions (undo awareness)

1 participant