Skip to content

Base retargeting support - #590

Open
skarim wants to merge 9 commits into
mainfrom
skarim/base-retargeting
Open

skarim wants to merge 9 commits into
mainfrom
skarim/base-retargeting

Conversation

@skarim

@skarim skarim commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Adds CLI support for base changes GitHub makes automatically when a stack's base branch is deleted. sync and rebase repair local history against the new server base without recreating the stack or its PRs.

Functionality and user impact

  • Follow automatic retargets. sync and rebase use GitHub's new base and the existing validated --onto cascade to replay the stack's own commits. The local trunk changes only after rebasing succeeds; continuation keeps the accepted target, and abort restores the old trunk.
  • Confirm removing unmerged base commits. If the old base is not already in the target or known to have merged into it, confirmation defaults to No. Automation can explicitly accept with --accept-base-change.
  • Stop publishing against a stale base. push and submit direct users to sync before publishing a retargeted stack.
  • Surface pending repair. view reports the new server base and marks the bottom branch's needsRebase in JSON without changing the saved local trunk. Remote checkout warns when an existing local stack still needs repair, and imports keep the merged first PR's old base so the next sync repairs the stack with the same consent checks.

Key areas to review

  • cmd/utils.go: shared single-stack base lookup, publishing guard, and consent/cutoff selection. Only a detected retarget switches the bottom branch to --onto; ordinary trunk rebases retain their existing behavior.
  • cmd/rebase.go and cmd/sync.go: target resolution, selected-range handling, and passing the cutoff into the existing rebase flow.
  • cmd/rebase_worktree.go: TargetTrunk is journaled separately from the applied trunk. Check completion/save retries and abort restoration, covered by the retarget recovery cases in cmd/rebase_test.go.
  • cmd/push.go, cmd/submit.go, cmd/view.go, and cmd/checkout.go: publishing guards and pending-repair reporting without implicit history rewrites. Arbitrary retargeting and branching-stack workflows remain out of scope.

Copilot AI max review requested due to automatic review settings October 25, 2026 13:33

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.

🔵 Needs a closer look

The history-rewriting and recovery changes have unresolved safety issues that require fixes and final human validation.

7 open issues
What changed in this PR

Adds base-retarget handling to gh stack, allowing existing stacks to follow GitHub’s new base without recreating their pull requests.

Changes:

  • Adds retarget detection, history repair, and --accept-base-change consent to sync and rebase.
  • Records the accepted target for rebase continuation and abort recovery.
  • Guards publishing against stale bases and reports pending repairs in view and checkout.
File Description
docs/​src/​content/​docs/​reference/​cli.md Documents retarget behavior and consent flags.
cmd/​view.go Reports retargets and marks JSON repair status.
cmd/​view_test.go Tests pending-repair reporting without trunk changes.
cmd/​utils.go Adds shared detection, publishing guards, and cutoff selection.
cmd/​sync.go Integrates retarget repair into synchronization.
cmd/​sync_test.go Tests repair, repeat runs, and conflict rollback.
cmd/​submit.go Blocks submission against a stale base.
cmd/​submit_test.go Tests retarget and lookup-failure guards.
cmd/​rebase.go Adds consent flags and target journaling.
cmd/​rebase_worktree.go Handles target publication and original-trunk restoration.
cmd/​rebase_test.go Tests retarget history, consent, and recovery.
cmd/​push.go Blocks pushing against a stale base.
cmd/​push_test.go Tests the retarget publishing guard.
cmd/​checkout.go Uses the server base and warns about pending repairs.
cmd/​checkout_test.go Tests tracked-stack warnings and import-base selection.

Review effort: Max

Comment thread cmd/sync.go
Comment thread cmd/utils.go Outdated
Comment thread cmd/rebase.go Outdated
Comment thread cmd/utils.go Outdated
Comment thread cmd/utils.go Outdated
Comment thread cmd/utils.go Outdated
Comment thread cmd/view.go Outdated
A merged branch below a retargeted stack can land in the old base after that
base merged. Check the boundary the cascade drops, and skip the prompt only
when those commits reached the new base.
Importing onto GitHub's new base hid the pending retarget, so the next rebase
skipped consent. Keep the merged first PR's base so sync repairs the stack, and
compare GitHub's base only for the tracked-stack warning.

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.

2 participants