Skip to content

feat: preserve session linkage after git rewrites#947

Draft
peyton-alt wants to merge 6 commits intomainfrom
peyton/post-rewrite-linkage
Draft

feat: preserve session linkage after git rewrites#947
peyton-alt wants to merge 6 commits intomainfrom
peyton/post-rewrite-linkage

Conversation

@peyton-alt
Copy link
Copy Markdown
Contributor

@peyton-alt peyton-alt commented Apr 14, 2026

Summary

Add CLI-side post-rewrite tracking so Entire preserves local session linkage after Git rewrites instead of relying on fallback relinking later.

This PR:

  • adds managed post-rewrite hook support
  • adds entire hooks git post-rewrite <rewrite-type> wiring
  • remaps local session BaseCommit and AttributionBaseCommit after amend and rebase
  • keeps LastCheckpointID unchanged so the checkpoint linkage follows the rewritten commit
  • documents the new hook behavior in strategy docs

Scope

Supported rewrite flows in this PR:

  • git commit --amend
  • git rebase
  • interactive rebase variants that route through post-rewrite, including reword, squash, and fixup

Not in scope here:

  • git reset
  • filter-repo / filter-branch
  • remote-only rewrites the CLI does not observe

Why

The goal is to keep Entire tracking native Git commands during an active session. Git already provides deterministic old-SHA -> new-SHA mappings through post-rewrite, so the CLI can preserve linkage locally without depending on UI/Darwin reconciliation or custom non-Git linkage metrics.

Verification

  • GOCACHE=/tmp/go-build go test ./cmd/entire/cli/strategy -run 'Test(ParsePostRewritePairs|ShadowStrategy_PostRewrite_)' -count=1 -v
  • GOCACHE=/tmp/go-build go test -tags=integration ./cmd/entire/cli/integration_test -run 'TestShadow_(AmendPreservesTrailer|PostRewriteAmendRemapsSessionState|PostRewriteRebaseRemapsSessionState)' -count=1 -v
  • Manual claude -p smoke test confirmed a real Entire-tracked commit still gets an Entire-Checkpoint trailer and session state in .git/entire-sessions; the follow-up live amend flow was not used as the primary verifier because Claude hit a write-permission prompt before completing the second turn.

Follow-up

A later PR can add lightweight reset/head-divergence guidance without coupling that to rewrite handling.


Note

Medium Risk
Adds a new managed post-rewrite git hook and updates session state/shadow-branch migration logic after amend/rebase, which could affect how checkpoints are linked and recovered across rewritten history.

Overview
Adds first-class support for Git’s post-rewrite hook so Entire can immediately preserve local checkpoint/session linkage after git commit --amend and git rebase.

The CLI now installs and exposes entire hooks git post-rewrite <rewrite-type>, and ManualCommitStrategy.PostRewrite parses old→new SHA mappings from stdin to remap per-worktree session state (BaseCommit and sometimes AttributionBaseCommit) while keeping LastCheckpointID stable.

Shadow-branch migration logic is refactored to a reusable migrateShadowBranchToBaseCommit helper and is reused during rewrites; tests are expanded with new unit + integration coverage for amend/rebase remapping and hook installation/command wiring, and docs are updated to mention post-rewrite behavior.

Reviewed by Cursor Bugbot for commit 01c8314. Configure here.

Copilot AI review requested due to automatic review settings April 14, 2026 03:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class post-rewrite hook handling to keep Entire’s manual-commit session linkage consistent after Git history rewrites (amend/rebase), so sessions continue to track the rewritten commits without relying on later fallback relinking.

Changes:

  • Add managed installation support for the post-rewrite Git hook and expose entire hooks git post-rewrite <rewrite-type>.
  • Implement ManualCommitStrategy.PostRewrite to remap session BaseCommit / AttributionBaseCommit based on Git-provided old→new SHA pairs.
  • Add unit + integration tests covering parsing and session state remapping behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/entire/cli/strategy/manual_commit_hooks.go Adds PostRewrite handler and post-rewrite input parsing.
cmd/entire/cli/strategy/manual_commit_session.go Introduces rewrite pair type + helper to remap session commit fields.
cmd/entire/cli/strategy/hooks.go Adds post-rewrite to managed hook list and installs hook script.
cmd/entire/cli/strategy/hooks_test.go Verifies managed hook names + hook installation includes post-rewrite.
cmd/entire/cli/hooks_git_cmd.go Wires post-rewrite subcommand into the hooks command tree.
cmd/entire/cli/hooks_git_cmd_test.go Ensures the new post-rewrite subcommand is discoverable and has the expected usage.
cmd/entire/cli/root_test.go Updates hidden-parent command-tree test to use the new hook leaf command.
cmd/entire/cli/strategy/manual_commit_test.go Adds unit tests for parsing + remapping behavior at the strategy layer.
cmd/entire/cli/integration_test/testenv.go Adds helper to invoke the post-rewrite hook with explicit mappings.
cmd/entire/cli/integration_test/phase_transitions_test.go Adds integration tests validating state remap for amend/rebase flows.
CLAUDE.md Documents the new post-rewrite hook behavior in strategy docs.

@peyton-alt
Copy link
Copy Markdown
Contributor Author

@BugBot review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 01c8314. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants