@@ -13,50 +13,21 @@ public class BranchConfigurationCalculator
1313 /// </summary>
1414 public static BranchConfig GetBranchConfiguration ( GitVersionContext context , Branch targetBranch , IList < Branch > excludedInheritBranches = null )
1515 {
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 )
3319 {
3420 Logger . WriteInfo ( string . Format (
3521 "No branch configuration found for branch {0}, falling back to default configuration" ,
3622 targetBranch . FriendlyName ) ) ;
3723
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 , "" ) ;
5726 }
5827
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 ;
6031 }
6132
6233 static BranchConfig InheritBranchConfiguration ( GitVersionContext context , Branch targetBranch , BranchConfig branchConfiguration , IList < Branch > excludedInheritBranches )
@@ -77,11 +48,9 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
7748 {
7849 excludedInheritBranches = repository . Branches . Where ( b =>
7950 {
80- var branchConfig = LookupBranchConfiguration ( config , b ) . ToArray ( ) ;
51+ var branchConfig = config . GetConfigForBranch ( b . FriendlyName ) ;
8152
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 ;
8554 } ) . ToList ( ) ;
8655 }
8756 // Add new excluded branches.
0 commit comments