@@ -11,21 +11,61 @@ namespace GitVersion.VersionCalculation;
11
11
12
12
internal sealed class TrunkBasedVersionStrategy : VersionStrategyBase
13
13
{
14
- private volatile int IterationCounter ;
14
+ private static readonly IReadOnlyCollection < ITrunkBasedContextPreEnricher > TrunkContextPreEnricherCollection = new ITrunkBasedContextPreEnricher [ ]
15
+ {
16
+ new EnrichSemanticVersion ( ) ,
17
+ new EnrichIncrement ( )
18
+ } ;
19
+ private static readonly IReadOnlyCollection < ITrunkBasedContextPostEnricher > TrunkContextPostEnricherCollection = new ITrunkBasedContextPostEnricher [ ]
20
+ {
21
+ new RemoveSemanticVersion ( ) ,
22
+ new RemoveIncrement ( )
23
+ } ;
24
+ private static readonly IReadOnlyCollection < ITrunkBasedIncrementer > TrunkIncrementerCollection = new ITrunkBasedIncrementer [ ]
25
+ {
26
+ // Trunk
27
+ new CommitOnTrunk ( ) ,
15
28
16
- private ITaggedSemanticVersionRepository TaggedSemanticVersionRepository { get ; }
29
+ new CommitOnTrunkWithPreReleaseTag ( ) ,
30
+ new LastCommitOnTrunkWithPreReleaseTag ( ) ,
17
31
18
- private IRepositoryStore RepositoryStore { get ; }
32
+ new CommitOnTrunkWithStableTag ( ) ,
33
+ new LastCommitOnTrunkWithStableTag ( ) ,
19
34
20
- private IIncrementStrategyFinder IncrementStrategyFinder { get ; }
35
+ new MergeCommitOnTrunk ( ) ,
36
+ new LastMergeCommitOnTrunk ( ) ,
37
+
38
+ new CommitOnTrunkBranchedToTrunk ( ) ,
39
+ new CommitOnTrunkBranchedToNonTrunk ( ) ,
40
+
41
+ // NonTrunk
42
+ new CommitOnNonTrunk ( ) ,
43
+ new CommitOnNonTrunkWithPreReleaseTag ( ) ,
44
+ new LastCommitOnNonTrunkWithPreReleaseTag ( ) ,
45
+
46
+ new CommitOnNonTrunkWithStableTag ( ) ,
47
+ new LastCommitOnNonTrunkWithStableTag ( ) ,
48
+
49
+ new MergeCommitOnNonTrunk ( ) ,
50
+ new LastMergeCommitOnNonTrunk ( ) ,
51
+
52
+ new CommitOnNonTrunkBranchedToTrunk ( ) ,
53
+ new CommitOnNonTrunkBranchedToNonTrunk ( )
54
+ } ;
55
+
56
+ private volatile int iterationCounter ;
57
+
58
+ private readonly ITaggedSemanticVersionRepository taggedSemanticVersionRepository ;
59
+ private readonly IRepositoryStore repositoryStore ;
60
+ private readonly IIncrementStrategyFinder incrementStrategyFinder ;
21
61
22
62
public TrunkBasedVersionStrategy ( Lazy < GitVersionContext > context , IRepositoryStore repositoryStore ,
23
63
ITaggedSemanticVersionRepository taggedSemanticVersionRepository , IIncrementStrategyFinder incrementStrategyFinder
24
64
) : base ( context )
25
65
{
26
- RepositoryStore = repositoryStore . NotNull ( ) ;
27
- TaggedSemanticVersionRepository = taggedSemanticVersionRepository . NotNull ( ) ;
28
- IncrementStrategyFinder = incrementStrategyFinder . NotNull ( ) ;
66
+ this . repositoryStore = repositoryStore . NotNull ( ) ;
67
+ this . taggedSemanticVersionRepository = taggedSemanticVersionRepository . NotNull ( ) ;
68
+ this . incrementStrategyFinder = incrementStrategyFinder . NotNull ( ) ;
29
69
}
30
70
31
71
public override IEnumerable < BaseVersion > GetBaseVersions ( EffectiveBranchConfiguration configuration )
@@ -34,7 +74,7 @@ public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfigur
34
74
35
75
var iteration = CreateIteration ( branchName : Context . CurrentBranch . Name , configuration : configuration . Value ) ;
36
76
37
- var taggedSemanticVersions = TaggedSemanticVersionRepository . GetAllTaggedSemanticVersions (
77
+ var taggedSemanticVersions = taggedSemanticVersionRepository . GetAllTaggedSemanticVersions (
38
78
Context . CurrentBranch , configuration . Value
39
79
) ;
40
80
@@ -52,7 +92,7 @@ public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfigur
52
92
private TrunkBasedIteration CreateIteration (
53
93
ReferenceName branchName , EffectiveConfiguration configuration , TrunkBasedIteration ? parent = null )
54
94
{
55
- var iterationCount = Interlocked . Increment ( ref IterationCounter ) ;
95
+ var iterationCount = Interlocked . Increment ( ref iterationCounter ) ;
56
96
return new TrunkBasedIteration (
57
97
id : $ "#{ iterationCount } ",
58
98
branchName : branchName ,
@@ -83,7 +123,7 @@ private bool IterateOverCommitsRecursive(
83
123
{
84
124
configuration = effectiveConfigurationWasBranchedFrom . Value ;
85
125
branchName = effectiveConfigurationWasBranchedFrom . Branch . Name ;
86
- taggedSemanticVersions = TaggedSemanticVersionRepository . GetAllTaggedSemanticVersions (
126
+ taggedSemanticVersions = taggedSemanticVersionRepository . GetAllTaggedSemanticVersions (
87
127
effectiveConfigurationWasBranchedFrom . Branch , effectiveConfigurationWasBranchedFrom . Value
88
128
) ;
89
129
}
@@ -103,7 +143,7 @@ private bool IterateOverCommitsRecursive(
103
143
if ( item . IsMergeCommit )
104
144
{
105
145
Lazy < IReadOnlyCollection < ICommit > > mergedCommitsInReverseOrderLazy = new (
106
- ( ) => IncrementStrategyFinder . GetMergedCommits ( item , 1 ) . Reverse ( ) . ToList ( )
146
+ ( ) => incrementStrategyFinder . GetMergedCommits ( item , 1 ) . Reverse ( ) . ToList ( )
107
147
) ;
108
148
109
149
if ( configuration . TrackMergeMessage
@@ -125,7 +165,7 @@ private bool IterateOverCommitsRecursive(
125
165
{
126
166
if ( configuration . IsMainline ) throw new NotImplementedException ( ) ;
127
167
mergedCommitsInReverseOrderLazy = new (
128
- ( ) => IncrementStrategyFinder . GetMergedCommits ( item , 0 ) . Reverse ( ) . ToList ( )
168
+ ( ) => incrementStrategyFinder . GetMergedCommits ( item , 0 ) . Reverse ( ) . ToList ( )
129
169
) ;
130
170
childConfiguration = configuration ;
131
171
}
@@ -162,10 +202,10 @@ private VersionField GetIncrementForcedByCommit(ICommit commit, EffectiveConfigu
162
202
163
203
return configuration . CommitMessageIncrementing switch
164
204
{
165
- CommitMessageIncrementMode . Enabled => IncrementStrategyFinder . GetIncrementForcedByCommit ( commit , configuration ) ,
205
+ CommitMessageIncrementMode . Enabled => incrementStrategyFinder . GetIncrementForcedByCommit ( commit , configuration ) ,
166
206
CommitMessageIncrementMode . Disabled => VersionField . None ,
167
207
CommitMessageIncrementMode . MergeMessageOnly => commit . IsMergeCommit
168
- ? IncrementStrategyFinder . GetIncrementForcedByCommit ( commit , configuration ) : VersionField . None ,
208
+ ? incrementStrategyFinder . GetIncrementForcedByCommit ( commit , configuration ) : VersionField . None ,
169
209
_ => throw new InvalidEnumArgumentException (
170
210
nameof ( configuration . CommitMessageIncrementing ) , ( int ) configuration . CommitMessageIncrementing , typeof ( CommitMessageIncrementMode )
171
211
)
@@ -176,10 +216,10 @@ private IReadOnlyDictionary<ICommit, EffectiveBranchConfiguration> GetCommitsWas
176
216
{
177
217
Dictionary < ICommit , EffectiveBranchConfiguration > result = new ( ) ;
178
218
179
- var branch = RepositoryStore . FindBranch ( branchName ) ;
219
+ var branch = repositoryStore . FindBranch ( branchName ) ;
180
220
if ( branch is null ) return result ;
181
221
182
- var branchCommits = RepositoryStore . FindCommitBranchesWasBranchedFrom (
222
+ var branchCommits = repositoryStore . FindCommitBranchesWasBranchedFrom (
183
223
branch , Context . Configuration
184
224
) . ToList ( ) ;
185
225
@@ -290,46 +330,4 @@ private static IEnumerable<BaseVersionV2> GetIncrementSteps(TrunkBasedIteration
290
330
}
291
331
}
292
332
}
293
-
294
- private static readonly IReadOnlyCollection < ITrunkBasedContextPreEnricher > TrunkContextPreEnricherCollection = new ITrunkBasedContextPreEnricher [ ]
295
- {
296
- new EnrichSemanticVersion ( ) ,
297
- new EnrichIncrement ( )
298
- } ;
299
- private static readonly IReadOnlyCollection < ITrunkBasedContextPostEnricher > TrunkContextPostEnricherCollection = new ITrunkBasedContextPostEnricher [ ]
300
- {
301
- new RemoveSemanticVersion ( ) ,
302
- new RemoveIncrement ( )
303
- } ;
304
- private static readonly IReadOnlyCollection < ITrunkBasedIncrementer > TrunkIncrementerCollection = new ITrunkBasedIncrementer [ ]
305
- {
306
- // Trunk
307
- new CommitOnTrunk ( ) ,
308
-
309
- new CommitOnTrunkWithPreReleaseTag ( ) ,
310
- new LastCommitOnTrunkWithPreReleaseTag ( ) ,
311
-
312
- new CommitOnTrunkWithStableTag ( ) ,
313
- new LastCommitOnTrunkWithStableTag ( ) ,
314
-
315
- new MergeCommitOnTrunk ( ) ,
316
- new LastMergeCommitOnTrunk ( ) ,
317
-
318
- new CommitOnTrunkBranchedToTrunk ( ) ,
319
- new CommitOnTrunkBranchedToNonTrunk ( ) ,
320
-
321
- // NonTrunk
322
- new CommitOnNonTrunk ( ) ,
323
- new CommitOnNonTrunkWithPreReleaseTag ( ) ,
324
- new LastCommitOnNonTrunkWithPreReleaseTag ( ) ,
325
-
326
- new CommitOnNonTrunkWithStableTag ( ) ,
327
- new LastCommitOnNonTrunkWithStableTag ( ) ,
328
-
329
- new MergeCommitOnNonTrunk ( ) ,
330
- new LastMergeCommitOnNonTrunk ( ) ,
331
-
332
- new CommitOnNonTrunkBranchedToTrunk ( ) ,
333
- new CommitOnNonTrunkBranchedToNonTrunk ( )
334
- } ;
335
333
}
0 commit comments