@@ -210,9 +210,9 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch? branch, Config conf
210
210
}
211
211
}
212
212
213
- public SemanticVersion GetCurrentCommitTaggedVersion ( ICommit ? commit , string ? tagPrefix )
213
+ public SemanticVersion GetCurrentCommitTaggedVersion ( ICommit ? commit , string ? tagPrefix , bool handleDetachedBranch )
214
214
=> this . repository . Tags
215
- . SelectMany ( t => GetCurrentCommitSemanticVersions ( commit , tagPrefix , t ) )
215
+ . SelectMany ( t => GetCurrentCommitSemanticVersions ( commit , tagPrefix , t , handleDetachedBranch ) )
216
216
. Max ( ) ;
217
217
218
218
public IEnumerable < SemanticVersion > GetVersionTagsOnBranch ( IBranch branch , string ? tagPrefixRegex )
@@ -281,12 +281,20 @@ public bool IsCommitOnBranch(ICommit? baseVersionSource, IBranch branch, ICommit
281
281
private static bool IsReleaseBranch ( INamedReference branch , IEnumerable < KeyValuePair < string , BranchConfig > > releaseBranchConfig )
282
282
=> releaseBranchConfig . Any ( c => c . Value ? . Regex != null && Regex . IsMatch ( branch . Name . Friendly , c . Value . Regex ) ) ;
283
283
284
- private static IEnumerable < SemanticVersion > GetCurrentCommitSemanticVersions ( ICommit ? commit , string ? tagPrefix , ITag tag )
284
+ private IEnumerable < SemanticVersion > GetCurrentCommitSemanticVersions ( ICommit ? commit , string ? tagPrefix , ITag tag , bool handleDetachedBranch )
285
285
{
286
+ if ( commit == null )
287
+ return Array . Empty < SemanticVersion > ( ) ;
288
+
286
289
var targetCommit = tag . PeeledTargetCommit ( ) ;
290
+ if ( targetCommit == null )
291
+ return Array . Empty < SemanticVersion > ( ) ;
292
+
293
+ var commitToCompare = handleDetachedBranch ? FindMergeBase ( commit , targetCommit ) : commit ;
294
+
287
295
var tagName = tag . Name . Friendly ;
288
296
289
- return targetCommit != null && Equals ( targetCommit , commit ) && SemanticVersion . TryParse ( tagName , tagPrefix , out var version )
297
+ return Equals ( targetCommit , commitToCompare ) && SemanticVersion . TryParse ( tagName , tagPrefix , out var version )
290
298
? new [ ] { version }
291
299
: Array . Empty < SemanticVersion > ( ) ;
292
300
}
0 commit comments