@@ -12,9 +12,9 @@ public class BranchConfigurationCalculator
12
12
/// <summary>
13
13
/// Gets the <see cref="BranchConfig"/> for the current commit.
14
14
/// </summary>
15
- public static BranchConfig GetBranchConfiguration ( Commit currentCommit , IRepository repository , bool onlyEvaluateTrackedBranches , Config config , Branch currentBranch , IList < Branch > excludedInheritBranches = null )
15
+ public static BranchConfig GetBranchConfiguration ( GitVersionContext context , Branch targetBranch , IList < Branch > excludedInheritBranches = null )
16
16
{
17
- var matchingBranches = LookupBranchConfiguration ( config , currentBranch ) . ToArray ( ) ;
17
+ var matchingBranches = LookupBranchConfiguration ( context . FullConfiguration , targetBranch ) . ToArray ( ) ;
18
18
19
19
BranchConfig branchConfiguration ;
20
20
if ( matchingBranches . Length > 0 )
@@ -25,7 +25,7 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
25
25
{
26
26
Logger . WriteWarning ( string . Format (
27
27
"Multiple branch configurations match the current branch branchName of '{0}'. Using the first matching configuration, '{1}'. Matching configurations include: '{2}'" ,
28
- currentBranch . FriendlyName ,
28
+ targetBranch . FriendlyName ,
29
29
branchConfiguration . Name ,
30
30
string . Join ( "', '" , matchingBranches . Select ( b => b . Name ) ) ) ) ;
31
31
}
@@ -34,14 +34,14 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
34
34
{
35
35
Logger . WriteInfo ( string . Format (
36
36
"No branch configuration found for branch {0}, falling back to default configuration" ,
37
- currentBranch . FriendlyName ) ) ;
37
+ targetBranch . FriendlyName ) ) ;
38
38
39
39
branchConfiguration = new BranchConfig { Name = string . Empty } ;
40
- ConfigurationProvider . ApplyBranchDefaults ( config , branchConfiguration , "" ) ;
40
+ ConfigurationProvider . ApplyBranchDefaults ( context . FullConfiguration , branchConfiguration , "" ) ;
41
41
}
42
42
43
43
return branchConfiguration . Increment == IncrementStrategy . Inherit ?
44
- InheritBranchConfiguration ( onlyEvaluateTrackedBranches , repository , currentCommit , currentBranch , branchConfiguration , config , excludedInheritBranches ) :
44
+ InheritBranchConfiguration ( context , targetBranch , branchConfiguration , excludedInheritBranches ) :
45
45
branchConfiguration ;
46
46
}
47
47
@@ -60,16 +60,18 @@ static IEnumerable<BranchConfig> LookupBranchConfiguration([NotNull] Config conf
60
60
return config . Branches . Where ( b => Regex . IsMatch ( currentBranch . FriendlyName , "^" + b . Value . Regex , RegexOptions . IgnoreCase ) ) . Select ( kvp => kvp . Value ) ;
61
61
}
62
62
63
- static BranchConfig InheritBranchConfiguration ( bool onlyEvaluateTrackedBranches , IRepository repository , Commit currentCommit , Branch currentBranch , BranchConfig branchConfiguration , Config config , IList < Branch > excludedInheritBranches )
63
+ static BranchConfig InheritBranchConfiguration ( GitVersionContext context , Branch targetBranch , BranchConfig branchConfiguration , IList < Branch > excludedInheritBranches )
64
64
{
65
+ var repository = context . Repository ;
66
+ var config = context . FullConfiguration ;
65
67
using ( Logger . IndentLog ( "Attempting to inherit branch configuration from parent branch" ) )
66
68
{
67
- var excludedBranches = new [ ] { currentBranch } ;
69
+ var excludedBranches = new [ ] { targetBranch } ;
68
70
// Check if we are a merge commit. If so likely we are a pull request
69
- var parentCount = currentCommit . Parents . Count ( ) ;
71
+ var parentCount = context . CurrentCommit . Parents . Count ( ) ;
70
72
if ( parentCount == 2 )
71
73
{
72
- excludedBranches = CalculateWhenMultipleParents ( repository , currentCommit , ref currentBranch , excludedBranches ) ;
74
+ excludedBranches = CalculateWhenMultipleParents ( repository , context . CurrentCommit , ref targetBranch , excludedBranches ) ;
73
75
}
74
76
75
77
if ( excludedInheritBranches == null )
@@ -90,22 +92,25 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
90
92
}
91
93
var branchesToEvaluate = repository . Branches . Except ( excludedInheritBranches ) . ToList ( ) ;
92
94
93
- var branchPoint = currentBranch . FindCommitBranchWasBranchedFrom ( repository , excludedInheritBranches . ToArray ( ) ) ;
95
+ var branchPoint = context . RepostioryMetadataProvider
96
+ . FindCommitBranchWasBranchedFrom ( targetBranch , repository , excludedInheritBranches . ToArray ( ) ) ;
94
97
List < Branch > possibleParents ;
95
98
if ( branchPoint == BranchCommit . Empty )
96
99
{
97
- possibleParents = currentCommit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true )
100
+ possibleParents = context . RepostioryMetadataProvider . GetBranchesContainingCommit ( context . CurrentCommit , repository , branchesToEvaluate , true )
98
101
// It fails to inherit Increment branch configuration if more than 1 parent;
99
102
// therefore no point to get more than 2 parents
100
103
. Take ( 2 )
101
104
. ToList ( ) ;
102
105
}
103
106
else
104
107
{
105
- var branches = branchPoint . Commit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true ) . ToList ( ) ;
108
+ var branches = context . RepostioryMetadataProvider
109
+ . GetBranchesContainingCommit ( branchPoint . Commit , repository , branchesToEvaluate , true ) . ToList ( ) ;
106
110
if ( branches . Count > 1 )
107
111
{
108
- var currentTipBranches = currentCommit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true ) . ToList ( ) ;
112
+ var currentTipBranches = context . RepostioryMetadataProvider
113
+ . GetBranchesContainingCommit ( context . CurrentCommit , repository , branchesToEvaluate , true ) . ToList ( ) ;
109
114
possibleParents = branches . Except ( currentTipBranches ) . ToList ( ) ;
110
115
}
111
116
else
@@ -118,7 +123,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
118
123
119
124
if ( possibleParents . Count == 1 )
120
125
{
121
- var branchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , possibleParents [ 0 ] , excludedInheritBranches ) ;
126
+ var branchConfig = GetBranchConfiguration ( context , possibleParents [ 0 ] , excludedInheritBranches ) ;
122
127
return new BranchConfig ( branchConfiguration )
123
128
{
124
129
Increment = branchConfig . Increment ,
@@ -149,7 +154,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
149
154
Logger . WriteWarning ( errorMessage + Environment . NewLine + Environment . NewLine + "Falling back to " + branchName + " branch config" ) ;
150
155
151
156
// To prevent infinite loops, make sure that a new branch was chosen.
152
- if ( LibGitExtensions . IsSameBranch ( currentBranch , chosenBranch ) )
157
+ if ( LibGitExtensions . IsSameBranch ( targetBranch , chosenBranch ) )
153
158
{
154
159
Logger . WriteWarning ( "Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead." ) ;
155
160
return new BranchConfig ( branchConfiguration )
@@ -158,7 +163,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
158
163
} ;
159
164
}
160
165
161
- var inheritingBranchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , chosenBranch , excludedInheritBranches ) ;
166
+ var inheritingBranchConfig = GetBranchConfiguration ( context , chosenBranch , excludedInheritBranches ) ;
162
167
return new BranchConfig ( branchConfiguration )
163
168
{
164
169
Increment = inheritingBranchConfig . Increment ,
0 commit comments