@@ -2917,10 +2917,15 @@ export class CommandCenter {
2917
2917
try {
2918
2918
await item . run ( repository , opts ) ;
2919
2919
} catch ( err ) {
2920
- if ( err . gitErrorCode !== GitErrorCodes . DirtyWorkTree ) {
2920
+ if ( err . gitErrorCode !== GitErrorCodes . DirtyWorkTree && err . gitErrorCode !== GitErrorCodes . WorktreeAlreadyExists ) {
2921
2921
throw err ;
2922
2922
}
2923
2923
2924
+ if ( err . gitErrorCode === GitErrorCodes . WorktreeAlreadyExists ) {
2925
+ this . handleWorktreeError ( err ) ;
2926
+ return false ;
2927
+ }
2928
+
2924
2929
const stash = l10n . t ( 'Stash & Checkout' ) ;
2925
2930
const migrate = l10n . t ( 'Migrate Changes' ) ;
2926
2931
const force = l10n . t ( 'Force Checkout' ) ;
@@ -3458,37 +3463,45 @@ export class CommandCenter {
3458
3463
try {
3459
3464
await repository . worktree ( { name : name , path : worktreePath } ) ;
3460
3465
} catch ( err ) {
3461
- if ( err . gitErrorCode === GitErrorCodes . WorktreeAlreadyExists ) {
3462
- const errorMessage = err . stderr ;
3463
- const match = errorMessage . match ( / w o r k t r e e a t ' ( [ ^ ' ] + ) ' / ) || errorMessage . match ( / ' ( [ ^ ' ] + ) ' / ) ;
3464
- const path = match ? match [ 1 ] : undefined ;
3466
+ if ( err . gitErrorCode !== GitErrorCodes . WorktreeAlreadyExists ) {
3467
+ throw err ;
3468
+ }
3465
3469
3466
- if ( ! path ) {
3467
- return ;
3468
- }
3470
+ this . handleWorktreeError ( err ) ;
3471
+ return ;
3469
3472
3470
- const openWorktree = l10n . t ( 'Open in current window' ) ;
3471
- const openWorktreeInNewWindow = l10n . t ( 'Open in new window' ) ;
3472
- const message = l10n . t ( errorMessage || 'A worktree for branch \'{0}\' already exists at \'{1}\'.' , name , path ) ;
3473
- const choice = await window . showWarningMessage ( message , { modal : true } , openWorktree , openWorktreeInNewWindow ) ;
3473
+ }
3474
+ }
3474
3475
3475
- const worktreeRepository = this . model . getRepository ( path ) || this . model . getRepository ( Uri . file ( path ) ) ;
3476
+ private async handleWorktreeError ( err : any ) : Promise < void > {
3477
+ const errorMessage = err . stderr ;
3478
+ const match = errorMessage . match ( / w o r k t r e e a t ' ( [ ^ ' ] + ) ' / ) || errorMessage . match ( / ' ( [ ^ ' ] + ) ' / ) ;
3479
+ const path = match ? match [ 1 ] : undefined ;
3476
3480
3477
- if ( ! worktreeRepository ) {
3478
- return ;
3479
- }
3481
+ if ( ! path ) {
3482
+ return ;
3483
+ }
3480
3484
3481
- if ( choice === openWorktree ) {
3482
- await this . openWorktreeInCurrentWindow ( worktreeRepository ) ;
3483
- } else if ( choice === openWorktreeInNewWindow ) {
3484
- await this . openWorktreeInNewWindow ( worktreeRepository ) ;
3485
- }
3485
+ const worktreeRepository = this . model . getRepository ( path ) || this . model . getRepository ( Uri . file ( path ) ) ;
3486
3486
3487
- return ;
3488
- }
3487
+ if ( ! worktreeRepository ) {
3488
+ return ;
3489
+ }
3489
3490
3490
- throw err ;
3491
+ const openWorktree = l10n . t ( 'Open in current window' ) ;
3492
+ const openWorktreeInNewWindow = l10n . t ( 'Open in new window' ) ;
3493
+ const message = l10n . t ( errorMessage ) ;
3494
+ const choice = await window . showWarningMessage ( message , { modal : true } , openWorktree , openWorktreeInNewWindow ) ;
3495
+
3496
+
3497
+
3498
+ if ( choice === openWorktree ) {
3499
+ await this . openWorktreeInCurrentWindow ( worktreeRepository ) ;
3500
+ } else if ( choice === openWorktreeInNewWindow ) {
3501
+ await this . openWorktreeInNewWindow ( worktreeRepository ) ;
3491
3502
}
3503
+
3504
+ return ;
3492
3505
}
3493
3506
3494
3507
@command ( 'git.deleteWorktree' , { repository : true } )
0 commit comments