Skip to content

feat: handle squash-merged parent PRs with --onto rebase#10

Merged
boneskull merged 2 commits intomainfrom
squash-merge-handling
Jan 30, 2026
Merged

feat: handle squash-merged parent PRs with --onto rebase#10
boneskull merged 2 commits intomainfrom
squash-merge-handling

Conversation

@boneskull
Copy link
Copy Markdown
Owner

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..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

@boneskull
Copy link
Copy Markdown
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>
@boneskull boneskull force-pushed the squash-merge-handling branch from a3db95f to 1d0c001 Compare January 29, 2026 23:52
Copy link
Copy Markdown

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

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 CommitExists and RebaseOnto to the internal git wrapper.
  • Persists per-branch fork points in .git/config and 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>
@boneskull boneskull merged commit 85a9cc5 into main Jan 30, 2026
5 checks passed
@boneskull boneskull deleted the squash-merge-handling branch February 3, 2026 03:20
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.

2 participants