@@ -137,8 +137,14 @@ public ICommit GetBaseVersionSource(ICommit currentBranchTip)
137
137
throw new GitVersionException ( $ "Cannot find commit { currentBranchTip } . Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception ) ;
138
138
}
139
139
}
140
+
140
141
public IEnumerable < ICommit > GetMainlineCommitLog ( ICommit ? baseVersionSource , ICommit ? mainlineTip )
141
142
{
143
+ if ( mainlineTip is null )
144
+ {
145
+ return Enumerable . Empty < ICommit > ( ) ;
146
+ }
147
+
142
148
var filter = new CommitFilter
143
149
{
144
150
IncludeReachableFrom = mainlineTip ,
@@ -149,6 +155,7 @@ public IEnumerable<ICommit> GetMainlineCommitLog(ICommit? baseVersionSource, ICo
149
155
150
156
return this . repository . Commits . QueryBy ( filter ) ;
151
157
}
158
+
152
159
public IEnumerable < ICommit > GetMergeBaseCommits ( ICommit ? mergeCommit , ICommit ? mergedHead , ICommit ? findMergeBase )
153
160
{
154
161
var filter = new CommitFilter
@@ -289,20 +296,20 @@ static IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IEn
289
296
public Dictionary < string , List < IBranch > > GetMainlineBranches ( ICommit commit , IEnumerable < KeyValuePair < string , BranchConfig ? > > ? mainlineBranchConfigs ) =>
290
297
this . repository . Branches
291
298
. Where ( b => mainlineBranchConfigs ? . Any ( c => c . Value ? . Regex != null && Regex . IsMatch ( b . Name . Friendly , c . Value . Regex ) ) == true )
292
- . Select ( b => new
293
- {
294
- MergeBase = FindMergeBase ( b . Tip ! , commit ) ,
295
- Branch = b
296
- } )
297
- . Where ( a => a . MergeBase != null )
298
- . GroupBy ( b => b . MergeBase ! . Sha , b => b . Branch )
299
+ . Select ( b => new { Origin = FindBranchOrigin ( b , commit ) , Branch = b } )
300
+ . Where ( a => a . Origin != null )
301
+ . GroupBy ( b => b . Origin ? . Sha , b => b . Branch )
299
302
. ToDictionary ( b => b . Key , b => b . ToList ( ) ) ;
300
303
304
+ private ICommit FindBranchOrigin ( IBranch branch , ICommit commit ) =>
305
+ FindMergeBase ( branch . Tip ! , commit ) ?? FindCommitBranchWasBranchedFrom ( branch , null ) . Commit ;
306
+
307
+
301
308
/// <summary>
302
309
/// Find the commit where the given branch was branched from another branch.
303
310
/// If there are multiple such commits and branches, tries to guess based on commit histories.
304
311
/// </summary>
305
- public BranchCommit FindCommitBranchWasBranchedFrom ( IBranch branch , Config configuration , params IBranch [ ] excludedBranches )
312
+ public BranchCommit FindCommitBranchWasBranchedFrom ( IBranch branch , Config ? configuration , params IBranch [ ] excludedBranches )
306
313
{
307
314
if ( branch == null )
308
315
{
@@ -456,6 +463,7 @@ private IEnumerable<BranchCommit> GetMergeCommitsForBranch(IBranch branch, Confi
456
463
return findMergeBase == null ? BranchCommit . Empty : new BranchCommit ( findMergeBase , otherBranch ) ;
457
464
458
465
} )
466
+ . Where ( b => b . Commit is not null )
459
467
. OrderByDescending ( b => b . Commit . When )
460
468
. ToList ( ) ;
461
469
this . mergeBaseCommitsCache . Add ( branch , branchMergeBases ) ;
0 commit comments