Skip to content

feat: preserve session linkage after git rewrites#947

Open
peyton-alt wants to merge 7 commits intomainfrom
peyton/post-rewrite-linkage
Open

feat: preserve session linkage after git rewrites#947
peyton-alt wants to merge 7 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 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-rewrite to preserve Entire session linkage after history rewrites. The hook wiring now exposes entire hooks git post-rewrite <rewrite-type>, installs/manages the post-rewrite hook, 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, remaps BaseCommit/AttributionBaseCommit, and migrates existing shadow branch refs when needed while keeping LastCheckpointID stable.

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.

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

@peyton-alt
Copy link
Copy Markdown
Contributor Author

@BugBot review

@peyton-alt peyton-alt marked this pull request as ready for review April 15, 2026 05:55
@peyton-alt peyton-alt requested a review from a team as a code owner April 15, 2026 05:55
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 1 potential issue.

Fix All in Cursor

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.

Create PR

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)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2a6ef55. 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.

3 participants