diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs index df54d4173d..4e08eef9c8 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs @@ -11,15 +11,16 @@ namespace GitVersion.VersionCalculation; /// Increments if the tag is not the current commit. /// internal sealed class TaggedCommitVersionStrategy( - Lazy contextLazy, ILog log, + ILog log, + Lazy contextLazy, ITaggedSemanticVersionService taggedSemanticVersionService, IIncrementStrategyFinder incrementStrategyFinder) : IVersionStrategy { + private readonly ILog log = log.NotNull(); private readonly ITaggedSemanticVersionService taggedSemanticVersionService = taggedSemanticVersionService.NotNull(); private readonly Lazy contextLazy = contextLazy.NotNull(); private readonly IIncrementStrategyFinder incrementStrategyFinder = incrementStrategyFinder.NotNull(); - private readonly ILog log = log.NotNull(); private GitVersionContext Context => contextLazy.Value; @@ -43,30 +44,30 @@ private IEnumerable GetBaseVersionsInternal(EffectiveBranchConfigur var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null); - SemanticVersion semanticVersionTreshold = new(0, 0, 0); + var semanticVersionTreshold = SemanticVersion.Empty; List alternativeSemanticVersionsWithTag = []; - foreach (var semanticVersionWithTag in taggedSemanticVersions) + foreach (var semanticVersion in taggedSemanticVersions) { - if (!semanticVersionWithTag.Value.IsMatchForBranchSpecificLabel(label)) + if (!semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) { - alternativeSemanticVersionsWithTag.Add(semanticVersionWithTag); + alternativeSemanticVersionsWithTag.Add(semanticVersion); continue; } var alternativeSemanticVersionMax = alternativeSemanticVersionsWithTag.Max()?.Value; - var highestPossibleSemanticVersion = semanticVersionWithTag.Value.Increment( + var highestPossibleSemanticVersion = semanticVersion.Value.Increment( VersionField.Major, null, forceIncrement: true, alternativeSemanticVersionMax ); if (highestPossibleSemanticVersion.IsLessThan(semanticVersionTreshold, includePreRelease: false)) { this.log.Info( - $"The tag '{semanticVersionWithTag.Value}' is skipped because it will never be higher than other tags." + $"The tag '{semanticVersion.Value}' is skipped because it provides a lower base version than other tags." ); alternativeSemanticVersionsWithTag.Clear(); continue; } - var baseVersionSource = semanticVersionWithTag.Tag.Commit; + var baseVersionSource = semanticVersion.Tag.Commit; var increment = incrementStrategyFinder.DetermineIncrementedField( currentCommit: Context.CurrentCommit, baseVersionSource: baseVersionSource, @@ -74,10 +75,10 @@ private IEnumerable GetBaseVersionsInternal(EffectiveBranchConfigur configuration: configuration.Value, label: label ); - semanticVersionTreshold = semanticVersionWithTag.Value.Increment(increment, null, forceIncrement: true); + semanticVersionTreshold = semanticVersion.Value.Increment(increment, null, forceIncrement: true); yield return new BaseVersion( - $"Git tag '{semanticVersionWithTag.Tag.Name.Friendly}'", semanticVersionWithTag.Value, baseVersionSource) + $"Git tag '{semanticVersion.Tag.Name.Friendly}'", semanticVersion.Value, baseVersionSource) { Operator = new BaseVersionOperator {