@@ -8,7 +8,7 @@ namespace GitVersion
8
8
9
9
public class BranchConfigurationCalculator
10
10
{
11
- public static KeyValuePair < string , BranchConfig > GetBranchConfiguration ( Commit currentCommit , IRepository repository , bool onlyEvaluateTrackedBranches , Config config , Branch currentBranch )
11
+ public static KeyValuePair < string , BranchConfig > GetBranchConfiguration ( Commit currentCommit , IRepository repository , bool onlyEvaluateTrackedBranches , Config config , Branch currentBranch , IList < Branch > excludedInheritBranches = null )
12
12
{
13
13
var matchingBranches = config . Branches . Where ( b => Regex . IsMatch ( currentBranch . Name , "^" + b . Key , RegexOptions . IgnoreCase ) ) . ToArray ( ) ;
14
14
@@ -23,7 +23,7 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
23
23
24
24
if ( branchConfiguration . Increment == IncrementStrategy . Inherit )
25
25
{
26
- return InheritBranchConfiguration ( onlyEvaluateTrackedBranches , repository , currentCommit , currentBranch , keyValuePair , branchConfiguration , config ) ;
26
+ return InheritBranchConfiguration ( onlyEvaluateTrackedBranches , repository , currentCommit , currentBranch , keyValuePair , branchConfiguration , config , excludedInheritBranches ) ;
27
27
}
28
28
29
29
return keyValuePair ;
@@ -33,10 +33,7 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
33
33
throw new Exception ( string . Format ( format , currentBranch . Name , string . Join ( ", " , matchingBranches . Select ( b => b . Key ) ) ) ) ;
34
34
}
35
35
36
- static KeyValuePair < string , BranchConfig > InheritBranchConfiguration (
37
- bool onlyEvaluateTrackedBranches , IRepository repository , Commit currentCommit ,
38
- Branch currentBranch , KeyValuePair < string , BranchConfig > keyValuePair ,
39
- BranchConfig branchConfiguration , Config config )
36
+ static KeyValuePair < string , BranchConfig > InheritBranchConfiguration ( bool onlyEvaluateTrackedBranches , IRepository repository , Commit currentCommit , Branch currentBranch , KeyValuePair < string , BranchConfig > keyValuePair , BranchConfig branchConfiguration , Config config , IList < Branch > excludedInheritBranches )
40
37
{
41
38
Logger . WriteInfo ( "Attempting to inherit branch configuration from parent branch" ) ;
42
39
var excludedBranches = new [ ] { currentBranch } ;
@@ -70,18 +67,23 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
70
67
71
68
Logger . WriteInfo ( "HEAD is merge commit, this is likely a pull request using " + currentBranch . Name + " as base" ) ;
72
69
}
70
+ if ( excludedInheritBranches == null )
71
+ {
72
+ excludedInheritBranches = new List < Branch > ( ) ;
73
+ }
74
+ excludedBranches . ToList ( ) . ForEach ( excludedInheritBranches . Add ) ;
73
75
74
- var branchPoint = currentBranch . FindCommitBranchWasBranchedFrom ( repository , onlyEvaluateTrackedBranches , excludedBranches ) ;
76
+ var branchPoint = currentBranch . FindCommitBranchWasBranchedFrom ( repository , onlyEvaluateTrackedBranches , excludedInheritBranches . ToArray ( ) ) ;
75
77
76
78
List < Branch > possibleParents ;
77
79
if ( branchPoint . Sha == currentCommit . Sha )
78
80
{
79
- possibleParents = currentCommit . GetBranchesContainingCommit ( repository , true ) . Except ( excludedBranches ) . ToList ( ) ;
81
+ possibleParents = currentCommit . GetBranchesContainingCommit ( repository , true ) . Except ( excludedInheritBranches ) . ToList ( ) ;
80
82
}
81
83
else
82
84
{
83
- var branches = branchPoint . GetBranchesContainingCommit ( repository , true ) . Except ( excludedBranches ) . ToList ( ) ;
84
- var currentTipBranches = currentCommit . GetBranchesContainingCommit ( repository , true ) . Except ( excludedBranches ) . ToList ( ) ;
85
+ var branches = branchPoint . GetBranchesContainingCommit ( repository , true ) . Except ( excludedInheritBranches ) . ToList ( ) ;
86
+ var currentTipBranches = currentCommit . GetBranchesContainingCommit ( repository , true ) . Except ( excludedInheritBranches ) . ToList ( ) ;
85
87
possibleParents = branches
86
88
. Except ( currentTipBranches )
87
89
. ToList ( ) ;
@@ -97,7 +99,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
97
99
98
100
if ( possibleParents . Count == 1 )
99
101
{
100
- var branchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , possibleParents [ 0 ] ) . Value ;
102
+ var branchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , possibleParents [ 0 ] , excludedInheritBranches ) . Value ;
101
103
return new KeyValuePair < string , BranchConfig > (
102
104
keyValuePair . Key ,
103
105
new BranchConfig ( branchConfiguration )
0 commit comments