Skip to content

Add checkout pull request in worktree option#8513

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/add-worktree-checkout-option
Draft

Add checkout pull request in worktree option#8513
Copilot wants to merge 11 commits intomainfrom
copilot/add-worktree-checkout-option

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

  • Add new command pr.pickInWorktree in package.json (command definition)
  • Add localization string for the new command in package.nls.json
  • Add command palette visibility entry in package.json
  • Add menu entries in package.json for the PR context menu (view/item/context)
  • Implement the pr.pickInWorktree command in src/commands.ts
  • Use git extension API for worktree creation (per reviewer feedback)
  • Include fetch operation within progress scope (per reviewer feedback)
  • Move info message outside progress callback (per reviewer feedback)
  • Test the lint and build process

Summary

This PR adds a new context menu option "Checkout Pull Request in Worktree" that allows users to check out a PR branch in a git worktree instead of the main working directory. This enables reviewing colleagues' PRs without having to commit current work, stash changes, or deal with merge conflicts.

Implementation Details

  • Uses the git extension's createWorktree API
  • Shows save dialog for worktree location selection first
  • Progress indicator covers both fetch and worktree creation operations
  • Shows "Open in New Window" dialog after progress is finished (not blocking progress)
  • Command is only available in desktop VS Code (not in web environments) via !isWeb when clause
  • Uses telemetry to track feature usage
  • Handles errors gracefully and provides user-friendly error messages
Original prompt

This section details on the original issue you should resolve

<issue_title>New checkout pull request in worktree option for prs context menu</issue_title>
<issue_description>I'd like an option to checkout a pr in a worktree, as part of the pr view context menu. e.g.
Checkout Pull Request in worktree.

It would be a useful to for being able to review Colleagues prs without having to find a stopping point to commit my current code or having to deal with merge conflicts when unstashing code. Work trees seem like the perfect way to enable this flow, without headaches.

Thanks :)
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 13, 2026 09:33
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
… naming

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Add checkout pull request in worktree option for context menu Add checkout pull request in worktree option Feb 13, 2026
Copilot AI requested a review from alexr00 February 13, 2026 09:48
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@copilot, there's git extension API for worktrees. I've udpated git.d.ts so include that.

…l execution

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot, there's git extension API for worktrees. I've udpated git.d.ts so include that.

Updated to use the git extension's createWorktree API in commit 04c416a. Also added the API to src/api/api.d.ts since the Repository interface there was missing it.

Copilot AI requested a review from alexr00 February 13, 2026 10:52
src/commands.ts Outdated
Comment on lines 918 to 922
const openAction = vscode.l10n.t('Open in New Window');
const result = await vscode.window.showInformationMessage(
vscode.l10n.t('Worktree created for Pull Request #{0}', pullRequestModel.number),
openAction
);
Copy link
Member

Choose a reason for hiding this comment

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

@copilot This should happen after the progress is finished, otherwise the progress reports until this info is acked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the info message to after the progress completes in commit ad74445. The showInformationMessage call now happens after withProgress resolves.

src/commands.ts Outdated
Comment on lines 874 to 891
try {
await repositoryToUse.fetch({ remote: remoteName, ref: branchName });
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e);
Logger.appendLine(`Failed to fetch branch ${branchName}: ${errorMessage}`, logId);
// Continue even if fetch fails - the branch might already be available locally
}

// Ask user for worktree location
const repoRootPath = repositoryToUse.rootUri.fsPath;
const parentDir = pathLib.dirname(repoRootPath);
const defaultWorktreePath = pathLib.join(parentDir, `pr-${pullRequestModel.number}`);

const worktreeUri = await vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(defaultWorktreePath),
title: vscode.l10n.t('Select Worktree Location'),
saveLabel: vscode.l10n.t('Create Worktree'),
});
Copy link
Member

Choose a reason for hiding this comment

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

@copilot We should select the work tree location and fetch the branch in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to run fetch and worktree location selection in parallel using Promise.all in commit ad74445.

…after progress

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI requested a review from alexr00 February 13, 2026 11:07
src/commands.ts Outdated
const remoteName = pullRequestModel.remote.remoteName;

// Run fetch and worktree location selection in parallel
const [, worktreeUri] = await Promise.all([
Copy link
Member

Choose a reason for hiding this comment

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

@copilot the progress should start here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restructured the code in commit 766d8a0. The progress now starts before the fetch operation and covers both fetch and worktree creation. The dialog for selecting the worktree location is shown before the progress starts.

… scope

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI requested a review from alexr00 February 13, 2026 14:13
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.

New checkout pull request in worktree option for prs context menu

2 participants