Skip to content

fix(web): disable worktree checkout when the PR branch is already checked out - #42488

Open
morhaf-ko wants to merge 6 commits into
pingdotgg:mainfrom
morhaf-ko:fix/42402-pr-checkout-menu
Open

morhaf-ko wants to merge 6 commits into
pingdotgg:mainfrom
morhaf-ko:fix/42402-pr-checkout-menu

Conversation

@morhaf-ko

Copy link
Copy Markdown

Disable separate-worktree checkout when a same-repository PR's branch is already checked out in the selected project folder. Keep In this repository available and show Checked out here on the disabled option.

Fixes #42402

Each menu opening starts a branch-only subscription and follows HEAD changes while the menu stays open. Worktree checkout waits for the first branch result. PRs without a known same-repository head still go through the server's existing checkout check.

Verification

  • Reproduced with a disposable checkout of fix(server): relay-delivered webhook runs no longer export their spans to the relay #42450 on macOS 27.2.1 and Electron 44.10.1. On main the menu offered the action, and the server rejected it. With the fix, the menu explains the conflict and still offers local checkout. Switching away from the PR branch with the menu open enables worktree checkout. Switching back disables it again.
  • All 18 focused browser tests passed. The regressions cover the current branch, a different branch, a fork branch with the same name, a pending read, a changed branch when the menu reopens, and a branch change while the menu stays open.
  • vp run check:changed passed on 26d23193.

Before and after

Before, the separate-worktree option is enabled

After, the separate-worktree option is disabled with a reason

Review evidence

Tier 1. Four web files reuse the existing branch subscription and server guard. Opening the menu starts an independent subscription that follows HEAD without starting remote status polling. An external checkout can briefly outrun the filesystem watcher, so the server remains authoritative when the action runs. The checkout menu has never owned the separate stacked-PR ref list.

The supplemental server test failed during collection. The desktop reproduction exercised the server guard on main.

Revert this PR to restore the previous menu behavior.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 24, 2026
@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request checkout menu now checks whether the pull request head branch is already checked out in the same repository. It disables separate-worktree checkout while checking or when that branch is already checked out.

Changes: Checkout branch status

Layer / File(s) Summary
Provide checkout status inputs
apps/web/src/state/vcs.ts, apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx, apps/web/src/components/pullRequest/PullRequestDetailActions.tsx
The VCS state module adds an environment-scoped branch subscription. The detail panel passes the head branch when its repository matches the pull request repository.
Use branch status in checkout menu
apps/web/src/components/pullRequest/PullRequestDetailActions.tsx, apps/web/src/components/pullRequest/PullRequestDetailPanel.permissions.browser.test.tsx
The menu checks branch status while open. It disables separate-worktree checkout while the query is pending or when the matching branch is already checked out, and updates the option description. Tests cover status updates, reopening the menu, and eligibility conditions.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: maria-rcks, juliusmarminge

Merge Risk: Minimal · up to 26d23

The checkout menu now disables separate-worktree checkout when the PR branch is already checked out here. The server guard is unchanged, so no concrete merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the separate-worktree checkout option is disabled when the PR branch is already checked out. It follows the conventional commit format, and the description and objecti…
Description check Passed The description follows the template. It has a clear problem statement (the menu offered worktree checkout that the server then rejected), a change explanation, a link to issue #42402 for scope, and a…
Linked Issues check Passed Directly linked issue #42402 requires four things: (1) detect that a same-repository PR head branch is checked out in the project folder, (2) explain the conflict in the checkout menu, (3) offer In th…
Out of Scope Changes check Passed All changed areas connect to #42402. PullRequestDetailActions.tsx adds the branch subscription, the disabled state, and the status text for the worktree option. PullRequestDetailPanel.tsx derives same…
Full details: Title check

Explanation

The title names the main change: the separate-worktree checkout option is disabled when the PR branch is already checked out. It follows the conventional commit format, and the description and objectives describe the same change. It does not list files and is not vague.

Full details: Description check

Explanation

The description follows the template. It has a clear problem statement (the menu offered worktree checkout that the server then rejected), a change explanation, a link to issue #42402 for scope, and a detailed verification section with reproduction steps, test counts, and before/after screenshots. It also names the model and harness only implicitly, and the template asks for the agent to be named if one was used, so this is a minor gap. The Problem and Scope headings are not labeled as sections, but their content is present.

Full details: Linked Issues check

Explanation

Directly linked issue #42402 requires four things: (1) detect that a same-repository PR head branch is checked out in the project folder, (2) explain the conflict in the checkout menu, (3) offer In this repository directly, and (4) keep the server guard. The diff to apps/web/src/components/pullRequest/PullRequestDetailActions.tsx covers (1) to (3). PullRequestCheckoutMenu receives sameRepositoryHead and opens a branch-only subscription (createCheckoutBranchSubscription in apps/web/src/state/vcs.ts) when the menu opens. It compares branch.data.refName with sameRepositoryHead. When they match, the separate-worktree MenuItem is disabled and its subtitle reads "Checked out here". The local checkout item is not disabled. While the read is pending, the item shows "Checking…" and stays disabled. A read error leaves the option enabled, so the server guard remains the backstop. The server guard in GitManager.ts is not changed by this PR, which covers (4). PullRequestDetailPanel.tsx passes sameRepositoryHead only when the head repository matches the PR repository. Browser tests in PullRequestDetailPanel.permissions.browser.test.tsx cover the matching, non-matching, and changed-branch cases, per the change summary. Sibling-worktree behavior (#38027) is out of scope and is not required. The supplemental server test failure during collection is a verification gap, not a missing requirement, because this PR does not change server behavior. This assessment relies on the diff and the change summary. I did not re-run the browser tests.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #42402. PullRequestDetailActions.tsx adds the branch subscription, the disabled state, and the status text for the worktree option. PullRequestDetailPanel.tsx derives sameRepositoryHead and passes it to the menu. vcs.ts adds createCheckoutBranchSubscription, which the menu needs. The permissions browser test file adds tests for this behavior. No change touches unrelated server logic, sibling-worktree handling, or the stacked-PR ref list. The change summary states that the checkout menu does not own that ref list, and no changed file in the summary touches it.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5d02075 and 26d2319.

Files selected for processing: 4

  • apps/web/src/components/pullRequest/PullRequestDetailActions.tsx
  • apps/web/src/components/pullRequest/PullRequestDetailPanel.permissions.browser.test.tsx
  • apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
  • apps/web/src/state/vcs.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR checkout offers a separate worktree for a branch already checked out in the project folder

2 participants