@@ -9,7 +9,7 @@ import { Command, commands, Disposable, MessageOptions, Position, ProgressLocati
9
9
import TelemetryReporter from '@vscode/extension-telemetry' ;
10
10
import { uniqueNamesGenerator , adjectives , animals , colors , NumberDictionary } from '@joaomoreno/unique-names-generator' ;
11
11
import { ForcePushMode , GitErrorCodes , RefType , Status , CommitOptions , RemoteSourcePublisher , Remote , Branch , Ref } from './api/git' ;
12
- import { Git , Stash } from './git' ;
12
+ import { Git , Stash , Worktree } from './git' ;
13
13
import { Model } from './model' ;
14
14
import { GitResourceGroup , Repository , Resource , ResourceGroupType } from './repository' ;
15
15
import { DiffEditorSelectionHunkToolbarContext , LineChange , applyLineChanges , getIndexDiffInformation , getModifiedRange , getWorkingTreeDiffInformation , intersectDiffWithRange , invertLineChange , toLineChanges , toLineRanges , compareLineChanges } from './staging' ;
@@ -57,6 +57,19 @@ class RefItemSeparator implements QuickPickItem {
57
57
constructor ( private readonly refType : RefType ) { }
58
58
}
59
59
60
+ class WorktreeItem implements QuickPickItem {
61
+
62
+ get label ( ) : string {
63
+ return `$(list-tree) ${ this . worktree . name } ` ;
64
+ }
65
+
66
+ get description ( ) : string {
67
+ return this . worktree . path ;
68
+ }
69
+
70
+ constructor ( readonly worktree : Worktree ) { }
71
+ }
72
+
60
73
class RefItem implements QuickPickItem {
61
74
62
75
get label ( ) : string {
@@ -215,6 +228,29 @@ class RemoteTagDeleteItem extends RefItem {
215
228
}
216
229
}
217
230
231
+ class WorktreeDeleteItem extends WorktreeItem {
232
+ async run ( mainRepository : Repository ) : Promise < void > {
233
+ if ( ! this . worktree . path ) {
234
+ return ;
235
+ }
236
+
237
+ try {
238
+ await mainRepository . deleteWorktree ( this . worktree . path ) ;
239
+ } catch ( err ) {
240
+ if ( err . gitErrorCode === GitErrorCodes . WorktreeContainsChanges ) {
241
+ const forceDelete = l10n . t ( 'Force Delete' ) ;
242
+ const message = l10n . t ( 'The worktree contains modified or untracked files. Do you want to force delete?' ) ;
243
+ const choice = await window . showWarningMessage ( message , { modal : true } , forceDelete ) ;
244
+
245
+ if ( choice === forceDelete ) {
246
+ await mainRepository . deleteWorktree ( this . worktree . path , { force : true } ) ;
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+
218
254
class MergeItem extends BranchItem {
219
255
220
256
async run ( repository : Repository ) : Promise < void > {
@@ -3420,6 +3456,32 @@ export class CommandCenter {
3420
3456
}
3421
3457
}
3422
3458
3459
+ @command ( 'git.deleteWorktreeFromPalette' )
3460
+ async deleteWorktreeFromPalette ( ) : Promise < void > {
3461
+ const mainRepository = this . model . repositories . find ( repo =>
3462
+ ! repo . dotGit . commonPath
3463
+ ) ;
3464
+
3465
+ if ( ! mainRepository ) {
3466
+ return ;
3467
+ }
3468
+
3469
+ const worktreePicks = async ( ) : Promise < WorktreeDeleteItem [ ] | QuickPickItem [ ] > => {
3470
+ const worktrees = await mainRepository . getWorktrees ( ) ;
3471
+ return worktrees . length === 0
3472
+ ? [ { label : l10n . t ( '$(info) This repository has no worktrees.' ) } ]
3473
+ : worktrees . map ( worktree => new WorktreeDeleteItem ( worktree ) ) ;
3474
+ } ;
3475
+
3476
+ const placeHolder = l10n . t ( 'Select a worktree to delete' ) ;
3477
+ const choice = await this . pickRef < WorktreeDeleteItem | QuickPickItem > ( worktreePicks ( ) , placeHolder ) ;
3478
+
3479
+ if ( choice instanceof WorktreeDeleteItem ) {
3480
+ await choice . run ( mainRepository ) ;
3481
+ }
3482
+ }
3483
+
3484
+
3423
3485
@command ( 'git.graph.deleteTag' , { repository : true } )
3424
3486
async deleteTag2 ( repository : Repository , historyItem ?: SourceControlHistoryItem , historyItemRefId ?: string ) : Promise < void > {
3425
3487
const historyItemRef = historyItem ?. references ?. find ( r => r . id === historyItemRefId ) ;
0 commit comments