Skip to content

skip pulling merged branches during remote checkout#16

Merged
skarim merged 2 commits intomainfrom
skarim/checkout-skip-merged-prs
Apr 13, 2026
Merged

skip pulling merged branches during remote checkout#16
skarim merged 2 commits intomainfrom
skarim/checkout-skip-merged-prs

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented Apr 13, 2026

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.

Copilot AI review requested due to automatic review settings April 13, 2026 17:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 resolvePR to accept cfg and 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.CreateBranch errors 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

Comment thread cmd/utils.go
Comment thread cmd/checkout.go
@skarim skarim force-pushed the skarim/checkout-skip-merged-prs branch from b144752 to 346a8ca Compare April 13, 2026 19:35
@skarim skarim merged commit e06284f into main Apr 13, 2026
13 checks passed
@skarim skarim deleted the skarim/checkout-skip-merged-prs branch April 13, 2026 22:36
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.

3 participants