@@ -349,7 +349,7 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
349
349
branchId = branch ?. id ?? getBranchId ( repoPath , false , tip ) ;
350
350
351
351
// Check if branch has commits that can be recomposed and get merge base
352
- const mergeBaseCommit = await this . getMergeBaseCommit ( branch , repoPath ) ;
352
+ const mergeBase = await this . getMergeBase ( branch , repoPath ) ;
353
353
354
354
context = {
355
355
webviewItem : `gitlens:branch${ head ? '+current' : '' } ${
@@ -362,7 +362,7 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
362
362
: ''
363
363
} ${ branch ?. starred ? '+starred' : '' } ${ branch ?. upstream ?. state . ahead ? '+ahead' : '' } ${
364
364
branch ?. upstream ?. state . behind ? '+behind' : ''
365
- } ${ mergeBaseCommit ? '+recomposable' : '' } `,
365
+ } ${ mergeBase ?. commit ? '+recomposable' : '' } `,
366
366
webviewItemValue : {
367
367
type : 'branch' ,
368
368
ref : createReference ( tip , repoPath , {
@@ -372,7 +372,9 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
372
372
remote : false ,
373
373
upstream : branch ?. upstream ,
374
374
} ) ,
375
- mergeBaseCommit : mergeBaseCommit ,
375
+ mergeBase : mergeBase && {
376
+ ...mergeBase ,
377
+ } ,
376
378
} ,
377
379
} ;
378
380
@@ -622,7 +624,10 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
622
624
return getCommitsForGraphCore . call ( this , defaultLimit , selectSha , undefined , cancellation ) ;
623
625
}
624
626
625
- private async getMergeBaseCommit ( branch : GitBranch | undefined , repoPath : string ) : Promise < string | undefined > {
627
+ private async getMergeBase (
628
+ branch : GitBranch | undefined ,
629
+ repoPath : string ,
630
+ ) : Promise < { commit : string ; branch : string ; remote : boolean } | undefined > {
626
631
if ( ! branch || branch . remote ) return undefined ;
627
632
628
633
try {
@@ -642,10 +647,10 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
642
647
643
648
// Select target with most recent common commit (closest to branch tip)
644
649
const validTargets = [ validStoredTarget , validStoredMergeBase ] ;
645
- const targetCommit = await this . selectMostRecentMergeBase ( branch . name , validTargets , svc ) ;
650
+ const mergeBase = await this . selectMostRecentMergeBase ( branch . name , validTargets , svc ) ;
646
651
647
- const isRecomposable = Boolean ( targetCommit && targetCommit !== branch . sha ) ;
648
- return isRecomposable ? targetCommit : undefined ;
652
+ const isRecomposable = Boolean ( mergeBase && mergeBase . commit !== branch . sha ) ;
653
+ return isRecomposable ? mergeBase : undefined ;
649
654
} catch {
650
655
// If we can't determine, assume not recomposable
651
656
return undefined ;
@@ -656,18 +661,29 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
656
661
branchName : string ,
657
662
targets : ( string | undefined ) [ ] ,
658
663
svc : ReturnType < typeof this . container . git . getRepositoryService > ,
659
- ) : Promise < string | undefined > {
664
+ ) : Promise < { commit : string ; branch : string ; remote : boolean } | undefined > {
665
+ const isString = ( t : string | undefined ) : t is string => Boolean ( t ) ;
660
666
const mergeBaseResults = await Promise . allSettled (
661
- targets . map ( target => target && svc . refs . getMergeBase ( branchName , target ) ) ,
667
+ targets . filter ( isString ) . map ( async target => {
668
+ const commit = await svc . refs . getMergeBase ( branchName , target ) ;
669
+ return {
670
+ commit : commit ,
671
+ branch : target ,
672
+ } ;
673
+ } ) ,
662
674
) ;
663
- const isString = ( t : string | undefined ) : t is string => Boolean ( t ) ;
664
- const mergeBases = mergeBaseResults . map ( result => getSettledValue ( result ) ) . filter ( isString ) ;
675
+ const mergeBases = mergeBaseResults
676
+ . map ( result => getSettledValue ( result ) )
677
+ . filter ( ( r ) : r is { commit : string ; branch : string ; remote : boolean } => isString ( r ?. commit ) ) ;
665
678
666
679
if ( mergeBases . length === 0 ) return undefined ;
667
680
668
681
let mostRecentMergeBase = mergeBases [ 0 ] ;
669
682
for ( let i = 1 ; i < mergeBases . length ; i ++ ) {
670
- const isCurrentMoreRecent = await svc . commits . isAncestorOf ( mostRecentMergeBase , mergeBases [ i ] ) ;
683
+ const isCurrentMoreRecent = await svc . commits . isAncestorOf (
684
+ mostRecentMergeBase ?. commit ,
685
+ mergeBases [ i ] . commit ,
686
+ ) ;
671
687
if ( isCurrentMoreRecent ) {
672
688
mostRecentMergeBase = mergeBases [ i ] ;
673
689
}
0 commit comments