@@ -12,9 +12,9 @@ public class BranchConfigurationCalculator
1212 /// <summary>
1313 /// Gets the <see cref="BranchConfig"/> for the current commit.
1414 /// </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 )
1616 {
17- var matchingBranches = LookupBranchConfiguration ( config , currentBranch ) . ToArray ( ) ;
17+ var matchingBranches = LookupBranchConfiguration ( context . FullConfiguration , targetBranch ) . ToArray ( ) ;
1818
1919 BranchConfig branchConfiguration ;
2020 if ( matchingBranches . Length > 0 )
@@ -25,7 +25,7 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
2525 {
2626 Logger . WriteWarning ( string . Format (
2727 "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 ,
2929 branchConfiguration . Name ,
3030 string . Join ( "', '" , matchingBranches . Select ( b => b . Name ) ) ) ) ;
3131 }
@@ -34,14 +34,14 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
3434 {
3535 Logger . WriteInfo ( string . Format (
3636 "No branch configuration found for branch {0}, falling back to default configuration" ,
37- currentBranch . FriendlyName ) ) ;
37+ targetBranch . FriendlyName ) ) ;
3838
3939 branchConfiguration = new BranchConfig { Name = string . Empty } ;
40- ConfigurationProvider . ApplyBranchDefaults ( config , branchConfiguration , "" ) ;
40+ ConfigurationProvider . ApplyBranchDefaults ( context . FullConfiguration , branchConfiguration , "" ) ;
4141 }
4242
4343 return branchConfiguration . Increment == IncrementStrategy . Inherit ?
44- InheritBranchConfiguration ( onlyEvaluateTrackedBranches , repository , currentCommit , currentBranch , branchConfiguration , config , excludedInheritBranches ) :
44+ InheritBranchConfiguration ( context , targetBranch , branchConfiguration , excludedInheritBranches ) :
4545 branchConfiguration ;
4646 }
4747
@@ -60,16 +60,18 @@ static IEnumerable<BranchConfig> LookupBranchConfiguration([NotNull] Config conf
6060 return config . Branches . Where ( b => Regex . IsMatch ( currentBranch . FriendlyName , "^" + b . Value . Regex , RegexOptions . IgnoreCase ) ) . Select ( kvp => kvp . Value ) ;
6161 }
6262
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 )
6464 {
65+ var repository = context . Repository ;
66+ var config = context . FullConfiguration ;
6567 using ( Logger . IndentLog ( "Attempting to inherit branch configuration from parent branch" ) )
6668 {
67- var excludedBranches = new [ ] { currentBranch } ;
69+ var excludedBranches = new [ ] { targetBranch } ;
6870 // 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 ( ) ;
7072 if ( parentCount == 2 )
7173 {
72- excludedBranches = CalculateWhenMultipleParents ( repository , currentCommit , ref currentBranch , excludedBranches ) ;
74+ excludedBranches = CalculateWhenMultipleParents ( repository , context . CurrentCommit , ref targetBranch , excludedBranches ) ;
7375 }
7476
7577 if ( excludedInheritBranches == null )
@@ -90,22 +92,25 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
9092 }
9193 var branchesToEvaluate = repository . Branches . Except ( excludedInheritBranches ) . ToList ( ) ;
9294
93- var branchPoint = currentBranch . FindCommitBranchWasBranchedFrom ( repository , excludedInheritBranches . ToArray ( ) ) ;
95+ var branchPoint = context . RepostioryMetadataProvider
96+ . FindCommitBranchWasBranchedFrom ( targetBranch , repository , excludedInheritBranches . ToArray ( ) ) ;
9497 List < Branch > possibleParents ;
9598 if ( branchPoint == BranchCommit . Empty )
9699 {
97- possibleParents = currentCommit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true )
100+ possibleParents = context . RepostioryMetadataProvider . GetBranchesContainingCommit ( context . CurrentCommit , repository , branchesToEvaluate , true )
98101 // It fails to inherit Increment branch configuration if more than 1 parent;
99102 // therefore no point to get more than 2 parents
100103 . Take ( 2 )
101104 . ToList ( ) ;
102105 }
103106 else
104107 {
105- var branches = branchPoint . Commit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true ) . ToList ( ) ;
108+ var branches = context . RepostioryMetadataProvider
109+ . GetBranchesContainingCommit ( branchPoint . Commit , repository , branchesToEvaluate , true ) . ToList ( ) ;
106110 if ( branches . Count > 1 )
107111 {
108- var currentTipBranches = currentCommit . GetBranchesContainingCommit ( repository , branchesToEvaluate , true ) . ToList ( ) ;
112+ var currentTipBranches = context . RepostioryMetadataProvider
113+ . GetBranchesContainingCommit ( context . CurrentCommit , repository , branchesToEvaluate , true ) . ToList ( ) ;
109114 possibleParents = branches . Except ( currentTipBranches ) . ToList ( ) ;
110115 }
111116 else
@@ -118,7 +123,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
118123
119124 if ( possibleParents . Count == 1 )
120125 {
121- var branchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , possibleParents [ 0 ] , excludedInheritBranches ) ;
126+ var branchConfig = GetBranchConfiguration ( context , possibleParents [ 0 ] , excludedInheritBranches ) ;
122127 return new BranchConfig ( branchConfiguration )
123128 {
124129 Increment = branchConfig . Increment ,
@@ -149,7 +154,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
149154 Logger . WriteWarning ( errorMessage + Environment . NewLine + Environment . NewLine + "Falling back to " + branchName + " branch config" ) ;
150155
151156 // To prevent infinite loops, make sure that a new branch was chosen.
152- if ( LibGitExtensions . IsSameBranch ( currentBranch , chosenBranch ) )
157+ if ( LibGitExtensions . IsSameBranch ( targetBranch , chosenBranch ) )
153158 {
154159 Logger . WriteWarning ( "Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead." ) ;
155160 return new BranchConfig ( branchConfiguration )
@@ -158,7 +163,7 @@ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches,
158163 } ;
159164 }
160165
161- var inheritingBranchConfig = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , chosenBranch , excludedInheritBranches ) ;
166+ var inheritingBranchConfig = GetBranchConfiguration ( context , chosenBranch , excludedInheritBranches ) ;
162167 return new BranchConfig ( branchConfiguration )
163168 {
164169 Increment = inheritingBranchConfig . Increment ,
0 commit comments