Skip to content

Sync before submit when a PR in the stack has merged - #62

Merged
DomBlack merged 1 commit into
mainfrom
sync-before-submit-when-merged
Oct 28, 2026
Merged

DomBlack merged 1 commit into
mainfrom
sync-before-submit-when-merged

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Hit this on the monorepo today: I created a branch on top of one whose PR had just merged, ran git ss without syncing first, and got a new PR with both commits in it. gh stack saw the merged PR, skipped that branch and based the new PR on main, but the local branch was still sitting on the merged branch's commit so the diff showed both. Our own result then listed the merged PR as "created" as well, which it wasn't.

The cause is that submit only knew a branch was merged from the merged flag in gh stack's metadata file, and gh stack is the only thing that sets that (during its own submit, i.e. too late). The fresh PR list submit fetches anyway already said the PR had merged, we just weren't looking at it.

So submit now reads merged from the forge too, and when any branch of the stack has merged it runs the normal sync before pushing anything: the merged branch is deleted, the ones above are restacked onto trunk, and the submit carries on from the stack as it is afterwards. If you were on the merged branch itself, a whole stack submit picks up from whatever is left (sync has moved you to trunk); git ss --down on it has nothing to do and says so. What the sync did is in the result and the CLI prints it above the submit lines; a dry run can't sync so it just names the branches and leaves them out of the plan. A merged branch that sync keeps (prune set to never, a dirty checkout) is skipped the way gh stack skips it, same as before.

Running git ss after the PR below had merged (but before a sync) pushed the
branch as it was: gh stack skipped the merged branch and based the new PR on
main, so it showed the merged commits as well as its own, and our result
claimed we'd "created" the merged PR too. The merged flag in the metadata is
only ever set by gh stack, so submit didn't know; the fresh PR list it fetches
anyway did.

So submit now treats a branch as merged when the forge says so, and when any
branch of the stack has merged it runs the normal sync first (merged branch
deleted, the ones above restacked onto trunk) and carries on from the stack as
it is afterwards. If the merged branch was the one checked out, a whole stack
submit picks up from whatever is left; a --down submit to it has nothing to do
and says so. The sync is in the result (and shown by the CLI), and a dry run
just names the branches and leaves them out of the plan.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 14:21
@DomBlack DomBlack added the bug Something isn't working label Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@DomBlack
DomBlack merged commit 641254d into main Oct 28, 2026
5 of 6 checks passed
@DomBlack
DomBlack deleted the sync-before-submit-when-merged branch October 28, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants