3
3
using GitVersion . Extensions ;
4
4
using GitVersion . Logging ;
5
5
using GitVersion . Model . Configuration ;
6
+ using GitVersion . Model . Exceptions ;
6
7
7
8
namespace GitVersion . Configuration ;
8
9
9
10
public class BranchConfigurationCalculator : IBranchConfigurationCalculator
10
11
{
11
12
private const string FallbackConfigName = "Fallback" ;
13
+ private const int MaxRecursions = 50 ;
12
14
13
15
private readonly ILog log ;
14
16
private readonly IRepositoryStore repositoryStore ;
15
- private readonly int _infiniteLoopProtectionLevel = 50 ;
16
17
17
18
public BranchConfigurationCalculator ( ILog log , IRepositoryStore repositoryStore )
18
19
{
@@ -23,11 +24,14 @@ public BranchConfigurationCalculator(ILog log, IRepositoryStore repositoryStore)
23
24
/// <summary>
24
25
/// Gets the <see cref="BranchConfig"/> for the current commit.
25
26
/// </summary>
26
- public BranchConfig GetBranchConfiguration ( int recursiveLevel , IBranch targetBranch , ICommit ? currentCommit , Config configuration , IList < IBranch > ? excludedInheritBranches = null )
27
+ public BranchConfig GetBranchConfiguration ( IBranch targetBranch , ICommit ? currentCommit , Config configuration , IList < IBranch > ? excludedInheritBranches = null ) =>
28
+ GetBranchConfigurationInternal ( 0 , targetBranch , currentCommit , configuration , excludedInheritBranches ) ;
29
+
30
+ private BranchConfig GetBranchConfigurationInternal ( int recursiveLevel , IBranch targetBranch , ICommit ? currentCommit , Config configuration , IList < IBranch > ? excludedInheritBranches = null )
27
31
{
28
- if ( recursiveLevel >= _infiniteLoopProtectionLevel )
32
+ if ( recursiveLevel >= MaxRecursions )
29
33
{
30
- throw new InfiniteLoopProtectionException ( "Inherited branch configuration caused an infinite loop...breaking. " ) ;
34
+ throw new InfiniteLoopProtectionException ( $ "Inherited branch configuration caused { recursiveLevel } recursions. Aborting! ") ;
31
35
}
32
36
33
37
var matchingBranches = configuration . GetConfigForBranch ( targetBranch . Name . WithoutRemote ) ;
@@ -56,6 +60,7 @@ public BranchConfig GetBranchConfiguration(int recursiveLevel, IBranch targetBra
56
60
}
57
61
58
62
return matchingBranches ;
63
+
59
64
}
60
65
61
66
// TODO I think we need to take a fresh approach to this.. it's getting really complex with heaps of edge cases
@@ -114,7 +119,7 @@ private BranchConfig InheritBranchConfiguration(int recursiveLevel, IBranch targ
114
119
115
120
if ( possibleParents . Count == 1 )
116
121
{
117
- var branchConfig = GetBranchConfiguration ( recursiveLevel , possibleParents [ 0 ] , currentCommit , configuration , excludedInheritBranches ) ;
122
+ var branchConfig = GetBranchConfigurationInternal ( recursiveLevel , possibleParents [ 0 ] , currentCommit , configuration , excludedInheritBranches ) ;
118
123
// If we have resolved a fallback config we should not return that we have got config
119
124
if ( branchConfig . Name != FallbackConfigName )
120
125
{
@@ -162,13 +167,14 @@ private BranchConfig InheritBranchConfiguration(int recursiveLevel, IBranch targ
162
167
} ;
163
168
}
164
169
165
- var inheritingBranchConfig = GetBranchConfiguration ( recursiveLevel , chosenBranch , currentCommit , configuration , excludedInheritBranches ) ! ;
170
+ var inheritingBranchConfig = GetBranchConfigurationInternal ( recursiveLevel , chosenBranch , currentCommit , configuration , excludedInheritBranches ) ! ;
166
171
var configIncrement = inheritingBranchConfig . Increment ;
167
172
if ( inheritingBranchConfig . Name ! . IsEquivalentTo ( FallbackConfigName ) && configIncrement == IncrementStrategy . Inherit )
168
173
{
169
174
this . log . Warning ( "Fallback config inherits by default, dropping to patch increment" ) ;
170
175
configIncrement = IncrementStrategy . Patch ;
171
176
}
177
+
172
178
return new BranchConfig ( branchConfiguration )
173
179
{
174
180
Increment = configIncrement ,
0 commit comments