@@ -142,11 +142,21 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
142
142
// To prevent infinite loops, make sure that a new branch was chosen.
143
143
if ( targetBranch . IsSameBranch ( chosenBranch ) )
144
144
{
145
- Logger . WriteWarning ( "Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead." ) ;
146
- return new BranchConfig ( branchConfiguration )
145
+ BranchConfig developOrMasterConfig =
146
+ ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem (
147
+ chosenBranch , branchConfiguration , config ) ;
148
+ if ( developOrMasterConfig != null )
147
149
{
148
- Increment = IncrementStrategy . Patch
149
- } ;
150
+ return developOrMasterConfig ;
151
+ }
152
+ else
153
+ {
154
+ Logger . WriteWarning ( "Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead." ) ;
155
+ return new BranchConfig ( branchConfiguration )
156
+ {
157
+ Increment = IncrementStrategy . Patch
158
+ } ;
159
+ }
150
160
}
151
161
152
162
var inheritingBranchConfig = GetBranchConfiguration ( context , chosenBranch , excludedInheritBranches ) ;
@@ -201,5 +211,39 @@ static Branch[] CalculateWhenMultipleParents(IRepository repository, Commit curr
201
211
202
212
return excludedBranches ;
203
213
}
214
+
215
+ private static BranchConfig
216
+ ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem ( Branch ChosenBranch ,
217
+ BranchConfig BranchConfiguration , Config config )
218
+ {
219
+ BranchConfig masterOrDevelopConfig = null ;
220
+ var developBranchRegex = config . Branches [ ConfigurationProvider . DevelopBranchKey ] . Regex ;
221
+ var masterBranchRegex = config . Branches [ ConfigurationProvider . MasterBranchKey ] . Regex ;
222
+ if ( Regex . IsMatch ( ChosenBranch . FriendlyName , developBranchRegex , RegexOptions . IgnoreCase ) )
223
+ {
224
+ // Normally we would not expect this to happen but for safety we add a check
225
+ if ( config . Branches [ ConfigurationProvider . DevelopBranchKey ] . Increment !=
226
+ IncrementStrategy . Inherit )
227
+ {
228
+ masterOrDevelopConfig = new BranchConfig ( BranchConfiguration )
229
+ {
230
+ Increment = config . Branches [ ConfigurationProvider . DevelopBranchKey ] . Increment
231
+ } ;
232
+ }
233
+ }
234
+ else if ( Regex . IsMatch ( ChosenBranch . FriendlyName , masterBranchRegex , RegexOptions . IgnoreCase ) )
235
+ {
236
+ // Normally we would not expect this to happen but for safety we add a check
237
+ if ( config . Branches [ ConfigurationProvider . MasterBranchKey ] . Increment !=
238
+ IncrementStrategy . Inherit )
239
+ {
240
+ masterOrDevelopConfig = new BranchConfig ( BranchConfiguration )
241
+ {
242
+ Increment = config . Branches [ ConfigurationProvider . DevelopBranchKey ] . Increment
243
+ } ;
244
+ }
245
+ }
246
+ return masterOrDevelopConfig ;
247
+ }
204
248
}
205
- }
249
+ }
0 commit comments