Fix stale merged PR badge on the default-branch worktree - #720
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.
95ad7a4 to
a78e330
Compare
|
Rebased on Still reproduces on current On the open question in the description — I've settled on Option A (suppress all PR badges on the default-branch worktree). It matches the report in #695 and keeps the guard in one spot. If you'd rather keep a currently-open sync PR visible there, that's a small follow-up on the same line and I'm happy to do it. No rush — just flagging that it's rebased and ready whenever it fits your queue. |
|
Sorry if I'm stalling on this. A bit unsure on the best way to tackle the problem, cause this solution might not be enough. |
|
Your hesitation was justified — I think my patch fixes this in the wrong place. I've put an alternative up as a branch rather than force-pushing over your review: compare: main...Snirpini:fix/sync-pr-matching The bottom line: instead of skipping the default-branch worktree in the reducer, drop any candidate in That keeps matching policy in one place (next to the
Why the reducer was the wrong placeThe Why head and base, and how #465 fitsChecking both keeps it principled rather than "hide things on On #465 — same root cause, reported earlier. One thing I couldn't make work: its suggested fix is to add the missing I've kept Two gaps I left out on purpose
I don't want to assume this is the right direction — you know the sidebar's constraints far better than I do. If you'd rather keep the original, or take neither and shape it differently, that's completely fine. And if there's something I haven't covered or a concern still sitting at the back of your mind, I'd genuinely like to hear it and help get it all covered properly. Happy to force-push into this PR, open a fresh one, or leave it — whichever suits you. |
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.)