Add worktree removal option when deleting PR branches#8559
Conversation
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
- Add SELECT_WORKTREE constant in settingKeys.ts - Add githubPullRequests.defaultDeletionMethod.selectWorktree setting in package.json - Add NLS description in package.nls.json - Add getWorktreeForBranch() and removeWorktree() methods to FolderRepositoryManager - Add worktree option to SelectedAction type and quick pick dropdown - Add worktree deletion to auto-delete flow (autoDeleteBranchesAfterMerge) - Ensure worktree removal happens before branch deletion in performBranchDeletion Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
alexr00
left a comment
There was a problem hiding this comment.
@copilot There are build failures:
extension:webworker:
asset test/index.js 6.61 MiB [emitted] (name: test/index) 1 related asset
asset extension.js 5.59 MiB [emitted] (name: extension) 1 related asset
ERROR in ./src/github/folderRepositoryManager.ts 4:0-41
Module not found: Error: Can't resolve 'child_process' in '/Users/runner/work/1/s/src/github'
extension:webworker compiled with 1 error in 63667 ms
Move git worktree operations (child_process/util) into dedicated env/node/gitWorktree.ts and env/browser/gitWorktree.ts modules, following the existing env pattern. The webpack alias ensures the browser/no-op version is used for the webworker target. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Fixed in bf66dd3. Moved the |
- Use repository.state.worktrees to find worktrees for a branch - Use repository.deleteWorktree() to remove worktrees - Add Worktree interface to api.d.ts - Remove env/node/gitWorktree.ts and env/browser/gitWorktree.ts - Remove webpack alias for gitWorktree Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Done in fb1e543. Replaced child_process exec with the git API — |
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
…pace check Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Done in 6ec5bea. Added |
Done in 7848e56. Added |
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
| }; | ||
|
|
||
| function isWorktreeInWorkspace(worktreePath: string): boolean { | ||
| return !!vscode.workspace.workspaceFolders?.some(folder => folder.uri.fsPath === worktreePath); |
There was a problem hiding this comment.
@copilot On windows this should be case insensitive compare
There was a problem hiding this comment.
Fixed in fe73c84. Now uses process.platform === 'win32' to apply .toLowerCase() on both paths before comparing, so Windows paths like C:\Users\... and c:\users\... match correctly.
…dows Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds first-class worktree cleanup support to the PR branch deletion flow so that deleting a merged PR branch can also remove its associated git worktree (avoiding stale worktree folders being left behind and potentially re-associated with other branches).
Changes:
- Adds a new setting
githubPullRequests.defaultDeletionMethod.selectWorktreeand surfaces a “Remove worktree {path}” option in the delete-branch quick pick (hidden when the worktree is a workspace folder). - Implements worktree detection/removal via the git extension API (
repository.state.worktrees+repository.deleteWorktree) and enforces removal-before-branch-deletion ordering. - Updates internal type definitions (
src/api/api.d.ts) to include worktree-related API surface (plus additional unrelated VS Code proposed chat type updates).
Reviewed changes
Copilot reviewed 5 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/github/pullRequestReviewCommon.ts | Adds worktree option to branch deletion quick pick, adds selectWorktree preference support, and ensures worktree removal happens before branch deletion. |
| src/github/folderRepositoryManager.ts | Adds worktree lookup/removal helpers backed by git extension API. |
| src/common/settingKeys.ts | Adds SELECT_WORKTREE setting key constant. |
| src/api/api.d.ts | Extends git API typings with Worktree, RepositoryState.worktrees, and Repository.{createWorktree,deleteWorktree}. |
| src/@types/vscode.proposed.chatSessionsProvider.d.ts | Updates proposed chat session typings (scope-unrelated to worktree feature). |
| src/@types/vscode.proposed.chatParticipantPrivate.d.ts | Updates proposed chat participant typings (scope-unrelated to worktree feature). |
| src/@types/vscode.proposed.chatParticipantAdditions.d.ts | Updates proposed chat participant typings (scope-unrelated to worktree feature). |
| package.nls.json | Adds localized description for the new selectWorktree setting. |
| package.json | Contributes the new githubPullRequests.defaultDeletionMethod.selectWorktree setting. |
Comments suppressed due to low confidence (1)
src/github/pullRequestReviewCommon.ts:417
- The new
worktreedeletion path can result indeletedBranchTypescontaining only'worktree', but the notification logic below only distinguishes local vs remote deletions and will currently fall into the "Deleted remote branch" message in that case. Please update the notification (and any other downstream handling) to explicitly handle worktree-only deletion and/or include worktree removal in the messaging.
const worktreeAction = selectedActions.find(a => a.type === 'worktree');
if (worktreeAction?.worktreePath) {
await folderRepositoryManager.removeWorktree(worktreeAction.worktreePath);
deletedBranchTypes.push(worktreeAction.type);
}
githubPullRequests.defaultDeletionMethod.selectWorktreegetWorktreeForBranch()using git extension APIremoveWorktree()using git extension APIselectWorktreepreferenceisWorktreeInWorkspaceat top levelisWorktreeInWorkspaceon WindowsOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.