feat: preserve session linkage after git rewrites#947
feat: preserve session linkage after git rewrites#947peyton-alt wants to merge 7 commits intomainfrom
Conversation
There was a problem hiding this comment.
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-rewriteGit hook and exposeentire hooks git post-rewrite <rewrite-type>. - Implement
ManualCommitStrategy.PostRewriteto remap sessionBaseCommit/AttributionBaseCommitbased 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. |
|
@BugBot review |
|
@BugBot review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Hardcoded prefix breaks chained post-rewrite hook script
- Changed generatePostRewriteChainedContent to accept cmdPrefix parameter and use it dynamically in the strings.Replace search/replacement instead of hardcoding 'entire', and updated all callers and tests accordingly.
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2a6ef55. Configure here.
| "$_entire_hook_dir/post-rewrite%s" "$@" < "$_entire_stdin" | ||
| fi | ||
| `, chainComment, backupSuffix, backupSuffix) | ||
| } |
There was a problem hiding this comment.
Hardcoded prefix breaks chained post-rewrite hook script
Medium Severity
generatePostRewriteChainedContent hardcodes entire hooks git post-rewrite "$1" 2>/dev/null || true as the strings.Replace search target, but buildHookSpecs generates hook content using the dynamic cmdPrefix parameter (e.g. go run ./cmd/entire/main.go in local_dev mode or a quoted absolute path for GUI git clients). When the prefix doesn't match "entire", strings.Replace is a no-op — the mktemp/cat/trap stdin-capture block is never injected, yet the chain block still references $_entire_stdin, causing the backup hook to fail with a bad redirect.
Reviewed by Cursor Bugbot for commit 2a6ef55. Configure here.



Summary
Add CLI-side
post-rewritetracking so Entire preserves local session linkage after Git rewrites instead of relying on fallback relinking later.This PR:
post-rewritehook supportentire hooks git post-rewrite <rewrite-type>wiringBaseCommitandAttributionBaseCommitafteramendandrebaseLastCheckpointIDunchanged so the checkpoint linkage follows the rewritten commitScope
Supported rewrite flows in this PR:
git commit --amendgit rebasepost-rewrite, includingreword,squash, andfixupNot in scope here:
git resetfilter-repo/filter-branchWhy
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 -vGOCACHE=/tmp/go-build go test -tags=integration ./cmd/entire/cli/integration_test -run 'TestShadow_(AmendPreservesTrailer|PostRewriteAmendRemapsSessionState|PostRewriteRebaseRemapsSessionState)' -count=1 -vclaude -psmoke test confirmed a real Entire-tracked commit still gets anEntire-Checkpointtrailer 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-rewritegit hook that mutates local session state and migrates shadow branches based on rewrite mappings; mistakes could break checkpoint linkage after rewrites across worktrees.Overview
Adds CLI support for Git
post-rewriteto preserve Entire session linkage after history rewrites. The hook wiring now exposesentire hooks git post-rewrite <rewrite-type>, installs/manages thepost-rewritehook, and updates docs accordingly.On
amend/rebase, the manual-commit strategy now parses old→new SHA pairs from stdin, finds sessions for the current worktree, remapsBaseCommit/AttributionBaseCommit, and migrates existing shadow branch refs when needed while keepingLastCheckpointIDstable.Tests are expanded across unit and integration suites to cover hook installation/chaining (including stdin replay for chained hooks) and amend/rebase rewrite flows, plus command-tree exposure.
Reviewed by Cursor Bugbot for commit 2a6ef55. Configure here.