feat: handle squash-merged parent PRs with --onto rebase#10
Merged
Conversation
Owner
Author
Stack
Managed by gh-stack |
When a parent PR is squash-merged into trunk, the original commits become unreachable. A simple 'git rebase trunk' would try to replay those commits, causing false conflicts. This change: - Adds RebaseOnto method (git rebase --onto) to git package - Adds CommitExists method for SHA validation - Stores fork points in git config (branch.<name>.stackForkPoint) - Records fork point when creating/adopting branches - Uses --onto rebase when fork point differs from current merge-base - Updates fork point after successful cascade - Cleans up fork point when orphaning branches - Sync now calculates fork points before deleting merged branches The fork point tracks where a branch originally diverged from its parent, enabling precise commit replay even after parent modification. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a3db95f to
1d0c001
Compare
There was a problem hiding this comment.
Pull request overview
Adds fork-point tracking and git rebase --onto support so stacked branches can be rebased correctly even when a parent PR was squash-merged (making the parent’s original commits unreachable).
Changes:
- Introduces
CommitExistsandRebaseOntoto the internal git wrapper. - Persists per-branch fork points in
.git/configand wires this into create/adopt/cascade/sync/orphan flows. - Adds unit tests covering fork point config and the new git operations.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/git/git.go | Adds CommitExists and RebaseOnto git helpers used by sync/cascade logic. |
| internal/git/git_test.go | Adds tests for CommitExists and RebaseOnto. |
| internal/config/config.go | Adds fork point storage/retrieval/removal in git config. |
| internal/config/config_test.go | Adds tests for fork point config behavior. |
| cmd/create.go | Records fork point when creating a stacked branch. |
| cmd/create_test.go | Adds coverage asserting fork point is stored during create flows. |
| cmd/adopt.go | Records fork point when adopting an existing branch into the stack. |
| cmd/adopt_test.go | Adds coverage asserting fork point is stored during adopt flows. |
| cmd/cascade.go | Uses fork point to decide when to rebase --onto and updates fork point after successful cascade. |
| cmd/sync.go | Retargets children of merged branches, collects fork points before deletion, and uses --onto where applicable. |
| cmd/orphan.go | Cleans up fork point metadata when orphaning branches (and descendants). |
| cmd/orphan_test.go | Adds coverage asserting fork point is removed when orphaning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Guard against panic when fork point is shorter than 8 chars - Update fork point after successful RebaseOnto in sync - Restore original branch after retargeting completes - Clarify RebaseOnto doc comment to match implementation - Fix TestRebaseOnto to detect trunk branch name dynamically Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a parent PR is squash-merged into trunk, the original commits
become unreachable. A simple 'git rebase trunk' would try to replay
those commits, causing false conflicts.
This change:
The fork point tracks where a branch originally diverged from its
parent, enabling precise commit replay even after parent modification.
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com