Fix stale merged PR badge on the default-branch worktree#720
Open
Snirpini wants to merge 1 commit into
Open
Conversation
A PR whose head is the repository's default branch is always a sync PR (e.g. main -> dev), never the default-branch worktree's own work. Because the default branch persists after such a PR merges, the newest merged head=<default> PR permanently matched the default-branch worktree and showed a stale merged PR badge. Skip PR association for the worktree on the repository's default branch in refreshRepositoryPullRequests. Fetch the default branch defensively so a transient gh failure falls back to the previous behavior instead of dropping every worktree's badge. Add reducer tests for both the skip and the defensive fallback.
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.
Closes #695
Summary
A worktree checked out on the repository's default branch showed a stale merged PR badge. Any PR whose
headRefNameis the default branch is a sync PR (e.g.main → dev), not the default-branch worktree's own work — and because the default branch persists after such a PR merges (unlike a feature branch, which is typically deleted), the newest mergedhead=<default>PR kept matching the default-branch worktree indefinitely.The fix skips PR association for the worktree whose name equals the repository's default branch, in
refreshRepositoryPullRequests— the point where PRs are mapped to worktrees. The default branch is fetched defensively withtry?: if that lookup fails, the refresh falls back to today's behavior rather than dropping every worktree's badge on a transientghhiccup.Scope — Option A. This suppresses all PR badges on the default-branch worktree, merged or open. It's the smallest, clearest change and matches the report: a clean default-branch worktree should show just the branch, with no PR attached. A narrower Option B — suppress only merged/closed
head=<default>PRs while still surfacing a currently-open sync PR — is also reasonable. I went with A, but the guard is localized to one spot, so switching to B (or adding it) would be a small follow-up there. Happy to change it if you'd prefer to keep open sync PRs visible on the default branch.Type of change
ready)How was this tested?
Two reducer tests added in
supacodeTests/RepositoriesFeatureTests.swift:repositoryPullRequestRefreshSkipsDefaultBranchWorktree— the default-branch worktree gets no PR even whenbatchPullRequestsreturns a mergedhead=mainPR for it, while a feature worktree still gets its PR. This reproduces Default branch worktree shows a stale merged PR #695 and fails without the fix.repositoryPullRequestRefreshAssignsWhenDefaultBranchLookupFails— when the default-branch lookup throws, the refresh still assigns by branch name, guarding the defensive fallback against a future regression.make checkpasses (format + lint)make testpasses (run withTEST_PARALLEL=NO)I built and ran the app to confirm the change works — verified via the automated tests above; I did not run the GUI app.
AI tool disclosure (optional)
Checklist
Closes #above.ready. (This is a bug fix; the issue is labeledready.)