sync: retarget upstack PRs on forge after deletion#1150
Merged
Conversation
Collaborator
Author
|
This change is part of the following stack: Change managed by git-spice. |
This was referenced May 12, 2026
a40644a to
979d0cd
Compare
42f7928 to
0694ab5
Compare
979d0cd to
3d9ac92
Compare
Collaborator
Author
|
Attempted to rename via gh rename api - but wound up closing. Attempting a push-then-repoint-then-delete workflow instead. |
3d9ac92 to
e4b5f2e
Compare
Add cycle detection to survivingAncestor so that if deleted branches form a cycle in their base references, the function falls back to trunk instead of looping forever.
`repo sync` and branch deletion both need to choose the next base when one or more downstack branches are being removed from consideration. Keeping that traversal in the branch graph gives both paths the same answer while leaving each caller responsible for its own removal policy. Sync now loads a branch graph for finished-branch detection and remote retargeting. The delete handler uses the same graph operation when moving local upstack branches around deleted bases.
`repo sync` should still retarget surviving upstack PRs when a finished downstack branch cannot be deleted from the local checkout. The local branch may remain because another worktree has it checked out, but the forge stack should no longer target a branch that was already merged there. The script keeps the local stack check separate from the forge assertion: `gs ls` verifies the starting stack shape, and the final ShamHub JSON verifies that the surviving PR targets trunk.
e4b5f2e to
ddbdacb
Compare
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
gs repo syncdeletes branches whose PRs were merged,upstack PRs on the forge are left targeting deleted branches.
This causes confusion on platforms like GitHub, where the PR
base no longer matches the local stack state.
This change retargets surviving upstack PRs on the forge to
their nearest surviving ancestor (or trunk if none exists)
after sync deletes merged branches. Cyclic base chains fall
back to trunk to avoid infinite loops.
Covered by unit tests for candidate collection and ancestor
resolution, plus test scripts exercising single-merge and
deep-stack scenarios end-to-end.
Regarding this question on #1073:
The issue encountered is branch corruption when adding the
gs bmcommand - which I will post later today on this stack. Prior to the merge command, the forge itself drove merge events and the sync/submit cycle pulled merge changes and drove repointing based on merges that happened elsewhere. When I added thegs bmcommand the flow was flipped, and the stack would become corrupted if you merged anything besides the bottom branch. I'll post a ref to that PR when I post it. It took me a minute to remember what had been happening and I needed claude to help me figure it out again 😂 . It provided this somewhat more verbose explanation:[skip changelog]: bug fix only