@@ -210,9 +210,9 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch? branch, Config conf
210210 }
211211 }
212212
213- public SemanticVersion GetCurrentCommitTaggedVersion ( ICommit ? commit , string ? tagPrefix )
213+ public SemanticVersion GetCurrentCommitTaggedVersion ( ICommit ? commit , string ? tagPrefix , bool handleDetachedBranch )
214214 => this . repository . Tags
215- . SelectMany ( t => GetCurrentCommitSemanticVersions ( commit , tagPrefix , t ) )
215+ . SelectMany ( t => GetCurrentCommitSemanticVersions ( commit , tagPrefix , t , handleDetachedBranch ) )
216216 . Max ( ) ;
217217
218218 public IEnumerable < SemanticVersion > GetVersionTagsOnBranch ( IBranch branch , string ? tagPrefixRegex )
@@ -281,12 +281,20 @@ public bool IsCommitOnBranch(ICommit? baseVersionSource, IBranch branch, ICommit
281281 private static bool IsReleaseBranch ( INamedReference branch , IEnumerable < KeyValuePair < string , BranchConfig > > releaseBranchConfig )
282282 => releaseBranchConfig . Any ( c => c . Value ? . Regex != null && Regex . IsMatch ( branch . Name . Friendly , c . Value . Regex ) ) ;
283283
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 )
285285 {
286+ if ( commit == null )
287+ return Array . Empty < SemanticVersion > ( ) ;
288+
286289 var targetCommit = tag . PeeledTargetCommit ( ) ;
290+ if ( targetCommit == null )
291+ return Array . Empty < SemanticVersion > ( ) ;
292+
293+ var commitToCompare = handleDetachedBranch ? FindMergeBase ( commit , targetCommit ) : commit ;
294+
287295 var tagName = tag . Name . Friendly ;
288296
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 )
290298 ? new [ ] { version }
291299 : Array . Empty < SemanticVersion > ( ) ;
292300 }
0 commit comments