Skip to content

Commit cddf40b

Browse files
author
Jake Ginnivan
committed
fix(config): When getting branch config, if we try to inherit branch config and get the fallback config, overwrite increment to not have an infinite inherit issue
1 parent 3c14826 commit cddf40b

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
2727
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
2828
}
2929

30-
return matchingBranches.Increment == IncrementStrategy.Inherit ?
31-
InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches) :
32-
matchingBranches;
30+
if (matchingBranches.Increment == IncrementStrategy.Inherit)
31+
{
32+
matchingBranches = InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches);
33+
if (matchingBranches.Name == FallbackConfigName && matchingBranches.Increment == IncrementStrategy.Inherit)
34+
{
35+
// We tried, and failed to inherit, just fall back to patch
36+
matchingBranches.Increment = IncrementStrategy.Patch;
37+
}
38+
}
39+
40+
return matchingBranches;
3341
}
3442

43+
// TODO I think we need to take a fresh approach to this.. it's getting really complex with heaps of edge cases
3544
static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch targetBranch, BranchConfig branchConfiguration, IList<Branch> excludedInheritBranches)
3645
{
3746
var repository = context.Repository;
@@ -94,13 +103,36 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
94103
if (possibleParents.Count == 1)
95104
{
96105
var branchConfig = GetBranchConfiguration(context, possibleParents[0], excludedInheritBranches);
97-
return new BranchConfig(branchConfiguration)
106+
// If we have resolved a fallback config we should not return that we have got config
107+
if (branchConfig.Name != FallbackConfigName)
98108
{
99-
Increment = branchConfig.Increment,
100-
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
101-
// If we are inheriting from develop then we should behave like develop
102-
TracksReleaseBranches = branchConfig.TracksReleaseBranches
103-
};
109+
return new BranchConfig(branchConfiguration)
110+
{
111+
Increment = branchConfig.Increment,
112+
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
113+
// If we are inheriting from develop then we should behave like develop
114+
TracksReleaseBranches = branchConfig.TracksReleaseBranches
115+
};
116+
}
117+
}
118+
119+
if (possibleParents.Count > 1)
120+
{
121+
// Lets try and get the branch config for each possible parent, the first may not have config
122+
foreach (var possibleParent in possibleParents)
123+
{
124+
var branchConfig = GetBranchConfiguration(context, possibleParent, excludedInheritBranches);
125+
if (branchConfig.Name != FallbackConfigName)
126+
{
127+
return new BranchConfig(branchConfiguration)
128+
{
129+
Increment = branchConfig.Increment,
130+
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
131+
// If we are inheriting from develop then we should behave like develop
132+
TracksReleaseBranches = branchConfig.TracksReleaseBranches
133+
};
134+
}
135+
}
104136
}
105137

106138
// If we fail to inherit it is probably because the branch has been merged and we can't do much. So we will fall back to develop's config

0 commit comments

Comments
 (0)