@@ -107,7 +107,7 @@ public IBranch GetTargetBranch(string? targetBranchName)
107107 public IBranch ? FindMainBranch ( GitVersionConfiguration configuration )
108108 {
109109 var mainBranchRegex = configuration . Branches [ ConfigurationConstants . MainBranchKey ] . Regex
110- ?? configuration . Branches [ ConfigurationConstants . MasterBranchKey ] . Regex ;
110+ ?? configuration . Branches [ ConfigurationConstants . MasterBranchKey ] . Regex ;
111111
112112 if ( mainBranchRegex == null )
113113 {
@@ -118,6 +118,20 @@ public IBranch GetTargetBranch(string? targetBranchName)
118118 Regex . IsMatch ( b . Name . Friendly , mainBranchRegex , RegexOptions . IgnoreCase ) ) ;
119119 }
120120
121+ public IEnumerable < IBranch > FindMainlineBranches ( GitVersionConfiguration configuration )
122+ {
123+ configuration . NotNull ( ) ;
124+
125+ foreach ( var branch in this . repository . Branches )
126+ {
127+ var branchConfiguration = configuration . GetBranchConfiguration ( branch ) ;
128+ if ( branchConfiguration . IsMainline == true )
129+ {
130+ yield return branch ;
131+ }
132+ }
133+ }
134+
121135 public IEnumerable < IBranch > GetReleaseBranches ( IEnumerable < KeyValuePair < string , BranchConfiguration > > releaseBranchConfig )
122136 => this . repository . Branches . Where ( b => IsReleaseBranch ( b , releaseBranchConfig ) ) ;
123137
@@ -243,37 +257,25 @@ public IEnumerable<SemanticVersion> GetVersionTagsOnBranch(IBranch branch, strin
243257
244258 using ( this . log . IndentLog ( $ "Getting version tags from branch '{ branch . Name . Canonical } '.") )
245259 {
246- var tags = GetValidVersionTags ( tagPrefixRegex , versionFormat ) ;
247- var tagsBySha = tags . Where ( t => t . Tag . TargetSha != null ) . ToLookup ( t => t . Tag . TargetSha , t => t ) ;
260+ var semanticVersions = GetSemanticVersionFromTags ( tagPrefixRegex , versionFormat ) ;
261+ var tagsBySha = semanticVersions . Where ( t => t . Tag . TargetSha != null ) . ToLookup ( t => t . Tag . TargetSha , t => t ) ;
248262
249- var versionTags = ( branch . Commits ? . SelectMany ( c => tagsBySha [ c . Sha ] . Select ( t => t . Semver ) ) ?? Enumerable . Empty < SemanticVersion > ( ) ) . ToList ( ) ;
263+ var versionTags = ( branch . Commits ? . SelectMany ( c => tagsBySha [ c . Sha ] . Select ( t => t . Value ) ) ?? Enumerable . Empty < SemanticVersion > ( ) ) . ToList ( ) ;
250264
251265 this . semanticVersionTagsOnBranchCache . Add ( branch , versionTags ) ;
252266 return versionTags ;
253267 }
254268 }
255269
256- public IEnumerable < ( ITag Tag , SemanticVersion Semver , ICommit Commit ) > GetValidVersionTags ( string ? tagPrefixRegex , SemanticVersionFormat versionFormat , DateTimeOffset ? olderThan = null )
270+ public IEnumerable < SemanticVersionWithTag > GetSemanticVersionFromTags ( string ? tagPrefixRegex , SemanticVersionFormat semanticVersionFormat )
257271 {
258- var tags = new List < ( ITag , SemanticVersion , ICommit ) > ( ) ;
259-
260272 foreach ( var tag in this . repository . Tags )
261273 {
262- if ( ! SemanticVersion . TryParse ( tag . Name . Friendly , tagPrefixRegex , out var semver , versionFormat ) )
263- continue ;
264-
265- var commit = tag . PeeledTargetCommit ( ) ;
266-
267- if ( commit == null )
268- continue ;
269-
270- if ( olderThan . HasValue && commit . When > olderThan . Value )
271- continue ;
272-
273- tags . Add ( ( tag , semver , commit ) ) ;
274+ if ( SemanticVersion . TryParse ( tag . Name . Friendly , tagPrefixRegex , out var semanticVersion , semanticVersionFormat ) )
275+ {
276+ yield return new SemanticVersionWithTag ( semanticVersion , tag ) ;
277+ }
274278 }
275-
276- return tags ;
277279 }
278280
279281 public IEnumerable < ICommit > GetCommitLog ( ICommit ? baseVersionSource , ICommit ? currentCommit )
@@ -302,15 +304,11 @@ private IEnumerable<SemanticVersion> GetCurrentCommitSemanticVersions(ICommit? c
302304 if ( commit == null )
303305 return Array . Empty < SemanticVersion > ( ) ;
304306
305- var targetCommit = tag . PeeledTargetCommit ( ) ;
306- if ( targetCommit == null )
307- return Array . Empty < SemanticVersion > ( ) ;
308-
309- var commitToCompare = handleDetachedBranch ? FindMergeBase ( commit , targetCommit ) : commit ;
307+ var commitToCompare = handleDetachedBranch ? FindMergeBase ( commit , tag . Commit ) : commit ;
310308
311309 var tagName = tag . Name . Friendly ;
312310
313- return Equals ( targetCommit , commitToCompare ) && SemanticVersion . TryParse ( tagName , tagPrefix , out var version , versionFormat )
311+ return Equals ( tag . Commit , commitToCompare ) && SemanticVersion . TryParse ( tagName , tagPrefix , out var version , versionFormat )
314312 ? new [ ] { version }
315313 : Array . Empty < SemanticVersion > ( ) ;
316314 }
0 commit comments