Skip to content

Fix stale merged PR badge on the default-branch worktree#720

Open
Snirpini wants to merge 1 commit into
supabitapp:mainfrom
Snirpini:fix/default-branch-stale-pr
Open

Fix stale merged PR badge on the default-branch worktree#720
Snirpini wants to merge 1 commit into
supabitapp:mainfrom
Snirpini:fix/default-branch-stale-pr

Conversation

@Snirpini

Copy link
Copy Markdown

Closes #695

Summary

A worktree checked out on the repository's default branch showed a stale merged PR badge. Any PR whose headRefName is 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 merged head=<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 with try?: if that lookup fails, the refresh falls back to today's behavior rather than dropping every worktree's badge on a transient gh hiccup.

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

  • Bug fix (the linked issue is a bug report)
  • Feature (the linked issue is a feature request marked ready)
  • Documentation
  • Other (please describe)

How was this tested?

Two reducer tests added in supacodeTests/RepositoriesFeatureTests.swift:

  • repositoryPullRequestRefreshSkipsDefaultBranchWorktree — the default-branch worktree gets no PR even when batchPullRequests returns a merged head=main PR 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 check passes (format + lint)

  • make test passes (run with TEST_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)

  • Model(s): Claude Opus 4.8
  • Harness / tools: Claude Code

Checklist

  • This pull request is linked to an issue with Closes # above.
  • For a feature, the linked issue is labeled ready. (This is a bug fix; the issue is labeled ready.)
  • I am the author of this work and accountable for it; no commit is authored or co-authored by an AI agent.
  • I have read the Contributing guide and the Code of Conduct.

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.
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.

Default branch worktree shows a stale merged PR

1 participant