@@ -99,13 +99,13 @@ class RefItem implements QuickPickItem {
99
99
100
100
get refName ( ) : string | undefined { return this . ref . name ; }
101
101
get refRemote ( ) : string | undefined { return this . ref . remote ; }
102
- get shortCommit ( ) : string { return ( this . ref . commit || '' ) . substr ( 0 , 8 ) ; }
102
+ get shortCommit ( ) : string { return ( this . ref . commit || '' ) . substring ( 0 , this . shortCommitLength ) ; }
103
103
104
104
private _buttons ?: QuickInputButton [ ] ;
105
105
get buttons ( ) : QuickInputButton [ ] | undefined { return this . _buttons ; }
106
106
set buttons ( newButtons : QuickInputButton [ ] | undefined ) { this . _buttons = newButtons ; }
107
107
108
- constructor ( protected readonly ref : Ref ) { }
108
+ constructor ( protected readonly ref : Ref , private readonly shortCommitLength : number ) { }
109
109
}
110
110
111
111
class BranchItem extends RefItem {
@@ -122,8 +122,8 @@ class BranchItem extends RefItem {
122
122
return description . length > 0 ? description . join ( '$(circle-small-filled)' ) : this . shortCommit ;
123
123
}
124
124
125
- constructor ( override readonly ref : Branch ) {
126
- super ( ref ) ;
125
+ constructor ( override readonly ref : Branch , shortCommitLength : number ) {
126
+ super ( ref , shortCommitLength ) ;
127
127
}
128
128
}
129
129
@@ -242,10 +242,10 @@ class RebaseUpstreamItem extends RebaseItem {
242
242
243
243
class HEADItem implements QuickPickItem {
244
244
245
- constructor ( private repository : Repository ) { }
245
+ constructor ( private repository : Repository , private readonly shortCommitLength : number ) { }
246
246
247
247
get label ( ) : string { return 'HEAD' ; }
248
- get description ( ) : string { return ( this . repository . HEAD && this . repository . HEAD . commit || '' ) . substr ( 0 , 8 ) ; }
248
+ get description ( ) : string { return ( this . repository . HEAD ?. commit ?? '' ) . substring ( 0 , this . shortCommitLength ) ; }
249
249
get alwaysShow ( ) : boolean { return true ; }
250
250
get refName ( ) : string { return 'HEAD' ; }
251
251
}
@@ -413,12 +413,7 @@ async function getRemoteRefItemButtons(repository: Repository) {
413
413
class RefProcessor {
414
414
protected readonly refs : Ref [ ] = [ ] ;
415
415
416
- get items ( ) : QuickPickItem [ ] {
417
- const items = this . refs . map ( r => new this . ctor ( r ) ) ;
418
- return items . length === 0 ? items : [ new RefItemSeparator ( this . type ) , ...items ] ;
419
- }
420
-
421
- constructor ( protected readonly type : RefType , protected readonly ctor : { new ( ref : Ref ) : QuickPickItem } = RefItem ) { }
416
+ constructor ( protected readonly type : RefType , protected readonly ctor : { new ( ref : Ref , shortCommitLength : number ) : QuickPickItem } = RefItem ) { }
422
417
423
418
processRef ( ref : Ref ) : boolean {
424
419
if ( ! ref . name && ! ref . commit ) {
@@ -431,9 +426,15 @@ class RefProcessor {
431
426
this . refs . push ( ref ) ;
432
427
return true ;
433
428
}
429
+
430
+ getItems ( shortCommitLength : number ) : QuickPickItem [ ] {
431
+ const items = this . refs . map ( r => new this . ctor ( r , shortCommitLength ) ) ;
432
+ return items . length === 0 ? items : [ new RefItemSeparator ( this . type ) , ...items ] ;
433
+ }
434
434
}
435
435
436
436
class RefItemsProcessor {
437
+ protected readonly shortCommitLength : number ;
437
438
438
439
constructor (
439
440
protected readonly repository : Repository ,
@@ -442,7 +443,10 @@ class RefItemsProcessor {
442
443
skipCurrentBranch ?: boolean ;
443
444
skipCurrentBranchRemote ?: boolean ;
444
445
} = { }
445
- ) { }
446
+ ) {
447
+ const config = workspace . getConfiguration ( 'git' , Uri . file ( repository . root ) ) ;
448
+ this . shortCommitLength = config . get < number > ( 'commitShortHashLength' , 7 ) ;
449
+ }
446
450
447
451
processRefs ( refs : Ref [ ] ) : QuickPickItem [ ] {
448
452
const refsToSkip = this . getRefsToSkip ( ) ;
@@ -460,7 +464,7 @@ class RefItemsProcessor {
460
464
461
465
const result : QuickPickItem [ ] = [ ] ;
462
466
for ( const processor of this . processors ) {
463
- result . push ( ...processor . items ) ;
467
+ result . push ( ...processor . getItems ( this . shortCommitLength ) ) ;
464
468
}
465
469
466
470
return result ;
@@ -483,19 +487,19 @@ class RefItemsProcessor {
483
487
484
488
class CheckoutRefProcessor extends RefProcessor {
485
489
486
- override get items ( ) : QuickPickItem [ ] {
490
+ constructor ( private readonly repository : Repository ) {
491
+ super ( RefType . Head ) ;
492
+ }
493
+
494
+ override getItems ( shortCommitLength : number ) : QuickPickItem [ ] {
487
495
const items = this . refs . map ( ref => {
488
496
return this . repository . isBranchProtected ( ref ) ?
489
- new CheckoutProtectedItem ( ref ) :
490
- new CheckoutItem ( ref ) ;
497
+ new CheckoutProtectedItem ( ref , shortCommitLength ) :
498
+ new CheckoutItem ( ref , shortCommitLength ) ;
491
499
} ) ;
492
500
493
501
return items . length === 0 ? items : [ new RefItemSeparator ( this . type ) , ...items ] ;
494
502
}
495
-
496
- constructor ( private readonly repository : Repository ) {
497
- super ( RefType . Head ) ;
498
- }
499
503
}
500
504
501
505
class CheckoutItemsProcessor extends RefItemsProcessor {
@@ -532,7 +536,7 @@ class CheckoutItemsProcessor extends RefItemsProcessor {
532
536
533
537
const result : QuickPickItem [ ] = [ ] ;
534
538
for ( const processor of this . processors ) {
535
- for ( const item of processor . items ) {
539
+ for ( const item of processor . getItems ( this . shortCommitLength ) ) {
536
540
if ( ! ( item instanceof RefItem ) ) {
537
541
result . push ( item ) ;
538
542
continue ;
@@ -3011,6 +3015,7 @@ export class CommandCenter {
3011
3015
3012
3016
const config = workspace . getConfiguration ( 'git' ) ;
3013
3017
const showRefDetails = config . get < boolean > ( 'showReferenceDetails' ) === true ;
3018
+ const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
3014
3019
3015
3020
if ( from ) {
3016
3021
const getRefPicks = async ( ) => {
@@ -3021,7 +3026,7 @@ export class CommandCenter {
3021
3026
new RefProcessor ( RefType . Tag )
3022
3027
] ) ;
3023
3028
3024
- return [ new HEADItem ( repository ) , ...refProcessors . processRefs ( refs ) ] ;
3029
+ return [ new HEADItem ( repository , commitShortHashLength ) , ...refProcessors . processRefs ( refs ) ] ;
3025
3030
} ;
3026
3031
3027
3032
const placeHolder = l10n . t ( 'Select a ref to create the branch from' ) ;
@@ -3233,6 +3238,7 @@ export class CommandCenter {
3233
3238
async rebase ( repository : Repository ) : Promise < void > {
3234
3239
const config = workspace . getConfiguration ( 'git' ) ;
3235
3240
const showRefDetails = config . get < boolean > ( 'showReferenceDetails' ) === true ;
3241
+ const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
3236
3242
3237
3243
const getQuickPickItems = async ( ) : Promise < QuickPickItem [ ] > => {
3238
3244
const refs = await repository . getRefs ( { includeCommitDetails : showRefDetails } ) ;
@@ -3251,7 +3257,7 @@ export class CommandCenter {
3251
3257
ref . name === `${ repository . HEAD ! . upstream ! . remote } /${ repository . HEAD ! . upstream ! . name } ` ) ;
3252
3258
3253
3259
if ( upstreamRef ) {
3254
- quickPickItems . splice ( 0 , 0 , new RebaseUpstreamItem ( upstreamRef ) ) ;
3260
+ quickPickItems . splice ( 0 , 0 , new RebaseUpstreamItem ( upstreamRef , commitShortHashLength ) ) ;
3255
3261
}
3256
3262
}
3257
3263
@@ -3292,10 +3298,13 @@ export class CommandCenter {
3292
3298
async deleteTag ( repository : Repository ) : Promise < void > {
3293
3299
const config = workspace . getConfiguration ( 'git' ) ;
3294
3300
const showRefDetails = config . get < boolean > ( 'showReferenceDetails' ) === true ;
3301
+ const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
3295
3302
3296
3303
const tagPicks = async ( ) : Promise < TagDeleteItem [ ] | QuickPickItem [ ] > => {
3297
3304
const remoteTags = await repository . getRefs ( { pattern : 'refs/tags' , includeCommitDetails : showRefDetails } ) ;
3298
- return remoteTags . length === 0 ? [ { label : l10n . t ( '$(info) This repository has no tags.' ) } ] : remoteTags . map ( ref => new TagDeleteItem ( ref ) ) ;
3305
+ return remoteTags . length === 0
3306
+ ? [ { label : l10n . t ( '$(info) This repository has no tags.' ) } ]
3307
+ : remoteTags . map ( ref => new TagDeleteItem ( ref , commitShortHashLength ) ) ;
3299
3308
} ;
3300
3309
3301
3310
const placeHolder = l10n . t ( 'Select a tag to delete' ) ;
@@ -3318,6 +3327,9 @@ export class CommandCenter {
3318
3327
3319
3328
@command ( 'git.deleteRemoteTag' , { repository : true } )
3320
3329
async deleteRemoteTag ( repository : Repository ) : Promise < void > {
3330
+ const config = workspace . getConfiguration ( 'git' ) ;
3331
+ const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
3332
+
3321
3333
const remotePicks = repository . remotes
3322
3334
. filter ( r => r . pushUrl !== undefined )
3323
3335
. map ( r => new RemoteItem ( repository , r ) ) ;
@@ -3354,7 +3366,9 @@ export class CommandCenter {
3354
3366
}
3355
3367
}
3356
3368
3357
- return remoteTags . length === 0 ? [ { label : l10n . t ( '$(info) Remote "{0}" has no tags.' , remoteName ) } ] : remoteTags . map ( ref => new RemoteTagDeleteItem ( ref ) ) ;
3369
+ return remoteTags . length === 0
3370
+ ? [ { label : l10n . t ( '$(info) Remote "{0}" has no tags.' , remoteName ) } ]
3371
+ : remoteTags . map ( ref => new RemoteTagDeleteItem ( ref , commitShortHashLength ) ) ;
3358
3372
} ;
3359
3373
3360
3374
const tagPickPlaceholder = l10n . t ( 'Select a remote tag to delete' ) ;
@@ -3442,6 +3456,9 @@ export class CommandCenter {
3442
3456
3443
3457
@command ( 'git.pullFrom' , { repository : true } )
3444
3458
async pullFrom ( repository : Repository ) : Promise < void > {
3459
+ const config = workspace . getConfiguration ( 'git' ) ;
3460
+ const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
3461
+
3445
3462
const remotes = repository . remotes ;
3446
3463
3447
3464
if ( remotes . length === 0 ) {
@@ -3464,7 +3481,7 @@ export class CommandCenter {
3464
3481
3465
3482
const getBranchPicks = async ( ) : Promise < RefItem [ ] > => {
3466
3483
const remoteRefs = await repository . getRefs ( { pattern : `refs/remotes/${ remoteName } /` } ) ;
3467
- return remoteRefs . map ( r => new RefItem ( r ) ) ;
3484
+ return remoteRefs . map ( r => new RefItem ( r , commitShortHashLength ) ) ;
3468
3485
} ;
3469
3486
3470
3487
const branchPlaceHolder = l10n . t ( 'Pick a branch to pull from' ) ;
0 commit comments