1
1
using System . Collections . Concurrent ;
2
2
using System . Text . RegularExpressions ;
3
+ using GitVersion . Common ;
3
4
using GitVersion . Configuration ;
4
5
using GitVersion . Extensions ;
5
6
@@ -16,19 +17,21 @@ internal class IncrementStrategyFinder : IIncrementStrategyFinder
16
17
private readonly Dictionary < string , VersionField ? > commitIncrementCache = new ( ) ;
17
18
private readonly Dictionary < string , Dictionary < string , int > > headCommitsMapCache = new ( ) ;
18
19
private readonly Dictionary < string , ICommit [ ] > headCommitsCache = new ( ) ;
19
- private readonly Lazy < IReadOnlySet < string ? > > tagsShaCache ;
20
20
21
21
private static readonly Regex DefaultMajorPatternRegex = new ( DefaultMajorPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
22
22
private static readonly Regex DefaultMinorPatternRegex = new ( DefaultMinorPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
23
23
private static readonly Regex DefaultPatchPatternRegex = new ( DefaultPatchPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
24
24
private static readonly Regex DefaultNoBumpPatternRegex = new ( DefaultNoBumpPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
25
25
26
26
private readonly IGitRepository repository ;
27
+ private readonly IRepositoryStore repositoryStore ;
27
28
28
- public IncrementStrategyFinder ( IGitRepository repository )
29
+ public IncrementStrategyFinder (
30
+ IGitRepository repository ,
31
+ IRepositoryStore repositoryStore )
29
32
{
30
33
this . repository = repository . NotNull ( ) ;
31
- this . tagsShaCache = new Lazy < IReadOnlySet < string ? > > ( ReadRepositoryTagsSha ) ;
34
+ this . repositoryStore = repositoryStore . NotNull ( ) ;
32
35
}
33
36
34
37
public VersionField DetermineIncrementedField ( ICommit ? currentCommit , BaseVersion baseVersion , EffectiveConfiguration configuration )
@@ -84,10 +87,16 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio
84
87
}
85
88
86
89
var commits = GetIntermediateCommits ( baseCommit , currentCommit ) ;
90
+ //get tags with valid version - depends on configuration (see #3757)
91
+ var versionTags = new Lazy < IReadOnlySet < string ? > > ( ( ) =>
92
+ this . repositoryStore . GetTaggedSemanticVersions ( configuration . TagPrefix , configuration . SemanticVersionFormat )
93
+ . Select ( x => x . Tag . TargetSha )
94
+ . ToHashSet ( ) ) ;
95
+
87
96
// consider commit messages since latest tag only (see #3071)
88
97
commits = commits
89
98
. Reverse ( )
90
- . TakeWhile ( x => ! this . tagsShaCache . Value . Contains ( x . Sha ) )
99
+ . TakeWhile ( x => ! versionTags . Value . Contains ( x . Sha ) )
91
100
. Reverse ( ) ;
92
101
93
102
if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . MergeMessageOnly )
@@ -104,8 +113,6 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio
104
113
) ;
105
114
}
106
115
107
- private IReadOnlySet < string ? > ReadRepositoryTagsSha ( ) => repository . Tags . Select ( t => t . TargetSha ) . ToHashSet ( ) ;
108
-
109
116
private static Regex TryGetRegexOrDefault ( string ? messageRegex , Regex defaultRegex ) =>
110
117
messageRegex == null
111
118
? defaultRegex
0 commit comments