Skip to content

Fix rebase when upstack head has moved - #614

Open
skarim wants to merge 1 commit into
mainfrom
skarim/fix-rebase-upstack-head-moved
Open

skarim wants to merge 1 commit into
mainfrom
skarim/fix-rebase-upstack-head-moved

Conversation

@skarim

@skarim skarim commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #598: recover the previous rebase boundary when a parent branch has advanced and local tracking is stale. Uses GitHub's recorded PR base SHA without weakening existing cutoff safety checks.

Functionality and user impact

  • Recover stale bases. rebase and sync can restack imported branches even when the local parent reflog cannot supply the old base.
  • Preserve safety. PR base metadata must match the local parent, and existing checks preserve newer valid cutoffs and merged-branch behavior. No additional API requests or recovery-format changes.

Key areas to review

  • PR metadata: internal/github/github.go reads baseRefOid in the existing PR queries.
  • Boundary refresh: updateBaseFromPR in cmd/utils.go reuses canUpdateBase; the rebase resolver itself is unchanged.
  • Regression coverage: cmd/rebase_test.go covers an imported stack with an advanced parent and no usable local fork point. The metadata tests cover parent mismatches and API-field propagation.

@skarim
skarim marked this pull request as ready for review November 3, 2026 18:31
Copilot AI max review requested due to automatic review settings November 3, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

PR base-cutoff recovery remains incomplete for fast-forwarded branches, conflict continuation, and queued parents, leaving valid imported-stack rebases vulnerable to failure.

3 open issues
What changed in this PR

Addresses #598 by using GitHub’s recorded PR base SHA to recover stale rebase boundaries when a parent branch has advanced, helping rebase and sync restack imported branches.

Changes:

  • Reads baseRefOid through existing PR queries without additional API requests.
  • Refreshes recorded cutoffs using parent-name and existing ancestry checks.
  • Adds regression coverage for imported stacks, parent mismatches, and API-field propagation.
File Description
internal/​github/​github.go Fetches and exposes PR base SHAs.
internal/​github/​github_test.go Verifies base SHA query and response propagation.
cmd/​utils.go Applies PR-derived cutoff refreshes during PR synchronization.
cmd/​utils_test.go Tests base adoption and preservation when parent names differ.
cmd/​rebase_test.go Tests imported-stack rebasing after a parent advances without a usable fork point.

Review effort: Max

Comment thread cmd/utils.go
}

func updateBaseFromPR(s *stack.Stack, b *stack.BranchRef, pr *github.PullRequest) {
if b.IsMerged() || pr.BaseRefOID == "" || pr.BaseRefName != s.ActiveBaseBranch(b.Branch) {
Comment thread cmd/utils.go
Comment on lines +703 to +704
if canUpdateBase(pr.BaseRefOID, b.Branch, b.Base) {
b.Base = pr.BaseRefOID
Comment thread cmd/utils.go
Comment on lines +703 to +704
if canUpdateBase(pr.BaseRefOID, b.Branch, b.Base) {
b.Base = pr.BaseRefOID

This branch has not been deployed

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

[Bug]: gh stack rebase fails whenever an upstack HEAD has moved

2 participants