@@ -13,50 +13,21 @@ public class BranchConfigurationCalculator
13
13
/// </summary>
14
14
public static BranchConfig GetBranchConfiguration ( GitVersionContext context , Branch targetBranch , IList < Branch > excludedInheritBranches = null )
15
15
{
16
- var matchingBranches = LookupBranchConfiguration ( context . FullConfiguration , targetBranch ) . ToArray ( ) ;
17
-
18
- BranchConfig branchConfiguration ;
19
- if ( matchingBranches . Length > 0 )
20
- {
21
- branchConfiguration = matchingBranches [ 0 ] ;
22
-
23
- if ( matchingBranches . Length > 1 )
24
- {
25
- Logger . WriteWarning ( string . Format (
26
- "Multiple branch configurations match the current branch branchName of '{0}'. Using the first matching configuration, '{1}'. Matching configurations include: '{2}'" ,
27
- targetBranch . FriendlyName ,
28
- branchConfiguration . Name ,
29
- string . Join ( "', '" , matchingBranches . Select ( b => b . Name ) ) ) ) ;
30
- }
31
- }
32
- else
16
+ var matchingBranches = context . FullConfiguration . GetConfigForBranch ( targetBranch . FriendlyName ) ;
17
+
18
+ if ( matchingBranches == null )
33
19
{
34
20
Logger . WriteInfo ( string . Format (
35
21
"No branch configuration found for branch {0}, falling back to default configuration" ,
36
22
targetBranch . FriendlyName ) ) ;
37
23
38
- branchConfiguration = new BranchConfig { Name = string . Empty } ;
39
- ConfigurationProvider . ApplyBranchDefaults ( context . FullConfiguration , branchConfiguration , "" ) ;
40
- }
41
-
42
- return branchConfiguration . Increment == IncrementStrategy . Inherit ?
43
- InheritBranchConfiguration ( context , targetBranch , branchConfiguration , excludedInheritBranches ) :
44
- branchConfiguration ;
45
- }
46
-
47
- static IEnumerable < BranchConfig > LookupBranchConfiguration ( Config config , Branch currentBranch )
48
- {
49
- if ( config == null )
50
- {
51
- throw new ArgumentNullException ( nameof ( config ) ) ;
52
- }
53
-
54
- if ( currentBranch == null )
55
- {
56
- throw new ArgumentNullException ( nameof ( currentBranch ) ) ;
24
+ matchingBranches = new BranchConfig { Name = string . Empty } ;
25
+ ConfigurationProvider . ApplyBranchDefaults ( context . FullConfiguration , matchingBranches , "" ) ;
57
26
}
58
27
59
- return config . Branches . Where ( b => Regex . IsMatch ( currentBranch . FriendlyName , "^" + b . Value . Regex , RegexOptions . IgnoreCase ) ) . Select ( kvp => kvp . Value ) ;
28
+ return matchingBranches . Increment == IncrementStrategy . Inherit ?
29
+ InheritBranchConfiguration ( context , targetBranch , matchingBranches , excludedInheritBranches ) :
30
+ matchingBranches ;
60
31
}
61
32
62
33
static BranchConfig InheritBranchConfiguration ( GitVersionContext context , Branch targetBranch , BranchConfig branchConfiguration , IList < Branch > excludedInheritBranches )
@@ -77,11 +48,9 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
77
48
{
78
49
excludedInheritBranches = repository . Branches . Where ( b =>
79
50
{
80
- var branchConfig = LookupBranchConfiguration ( config , b ) . ToArray ( ) ;
51
+ var branchConfig = config . GetConfigForBranch ( b . FriendlyName ) ;
81
52
82
- // NOTE: if length is 0 we couldn't find the configuration for the branch e.g. "origin/master"
83
- // NOTE: if the length is greater than 1 we cannot decide which merge strategy to pick
84
- return ( branchConfig . Length != 1 ) || ( branchConfig . Length == 1 && branchConfig [ 0 ] . Increment == IncrementStrategy . Inherit ) ;
53
+ return branchConfig != null && branchConfig . Increment == IncrementStrategy . Inherit ;
85
54
} ) . ToList ( ) ;
86
55
}
87
56
// Add new excluded branches.
0 commit comments