Skip to content

Commit 0f7e7b3

Browse files
authored
Merge pull request #1336 from JakeGinnivan/fix/PossibleInfiniteInherit
Fix/possible infinite inherit
2 parents e51c088 + 4c5d53e commit 0f7e7b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace GitVersion
88

99
public class BranchConfigurationCalculator
1010
{
11+
public static string FallbackConfigName = "Fallback";
12+
1113
/// <summary>
1214
/// Gets the <see cref="BranchConfig"/> for the current commit.
1315
/// </summary>
@@ -21,7 +23,7 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
2123
"No branch configuration found for branch {0}, falling back to default configuration",
2224
targetBranch.FriendlyName));
2325

24-
matchingBranches = new BranchConfig { Name = string.Empty };
26+
matchingBranches = new BranchConfig { Name = FallbackConfigName };
2527
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
2628
}
2729

@@ -65,7 +67,7 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
6567
List<Branch> possibleParents;
6668
if (branchPoint == BranchCommit.Empty)
6769
{
68-
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true)
70+
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, true)
6971
// It fails to inherit Increment branch configuration if more than 1 parent;
7072
// therefore no point to get more than 2 parents
7173
.Take(2)
@@ -135,9 +137,15 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
135137
}
136138

137139
var inheritingBranchConfig = GetBranchConfiguration(context, chosenBranch, excludedInheritBranches);
140+
var configIncrement = inheritingBranchConfig.Increment;
141+
if (inheritingBranchConfig.Name == FallbackConfigName && configIncrement == IncrementStrategy.Inherit)
142+
{
143+
Logger.WriteWarning("Fallback config inherits by default, dropping to patch increment");
144+
configIncrement = IncrementStrategy.Patch;
145+
}
138146
return new BranchConfig(branchConfiguration)
139147
{
140-
Increment = inheritingBranchConfig.Increment,
148+
Increment = configIncrement,
141149
PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion,
142150
// If we are inheriting from develop then we should behave like develop
143151
TracksReleaseBranches = inheritingBranchConfig.TracksReleaseBranches

0 commit comments

Comments
 (0)