skip pulling merged branches during remote checkout#16
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes remote stack checkout failures when some PRs in the stack are already merged and their head branches have been deleted upstream, by skipping over fully-merged stacks and tolerating missing merged branches during import.
Changes:
- Updates
resolvePRto acceptcfgand improves the “not found locally” guidance to direct users toward remote checkout by PR number. - Adds handling in remote checkout to short-circuit when all PRs in the remote stack are merged and to skip merged branches when branch creation fails.
- Adds test coverage for importing stacks where merged branches are deleted on the remote and for fully-merged stacks.
Show a summary per file
| File | Description |
|---|---|
| cmd/utils.go | resolvePR signature updated to take cfg; error message adjusted to guide users toward remote checkout. |
| cmd/utils_test.go | Updates tests to pass a test config into the new resolvePR signature. |
| cmd/merge.go | Updates call site to pass cfg into resolvePR. |
| cmd/checkout.go | Remote checkout: detect fully-merged stacks; during import, tolerate missing merged branches when creating local branches. |
| cmd/checkout_test.go | Adds regression tests for merged-branch-deleted import and fully-merged stack behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
cmd/checkout.go:486
git.CreateBrancherrors for merged PRs are currently swallowed unconditionally, which can hide real problems (e.g., permissions, corrupted repo, unexpected git failures) and still produces a local stack that references a branch that wasn't created. Consider only skipping when the failure indicates the remote ref is missing, or proactively skip pulling merged branches before calling CreateBranch so unexpected errors are still surfaced.
if err := git.CreateBranch(branch, remoteRef); err != nil {
if pr.Merged {
cfg.Infof("Skipping merged branch %s", branch)
continue
}
- Files reviewed: 5/5 changed files
- Comments generated: 2
ktravers
approved these changes
Apr 13, 2026
b144752 to
346a8ca
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.
Fixes a bug where
gh stack checkout <pr-number>would fail if part of the stack had been merged and the branches had been deleted, resulting in an error when attempting to pull the branch from remote.Merged PRs are now skipped when checking out a remote stack. If a stack has been fully merged, displays a message to the user directing them to start a new stack.