Skip to content

Fix/possible infinite inherit #1336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace GitVersion

public class BranchConfigurationCalculator
{
public static string FallbackConfigName = "Fallback";

/// <summary>
/// Gets the <see cref="BranchConfig"/> for the current commit.
/// </summary>
Expand All @@ -21,7 +23,7 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
"No branch configuration found for branch {0}, falling back to default configuration",
targetBranch.FriendlyName));

matchingBranches = new BranchConfig { Name = string.Empty };
matchingBranches = new BranchConfig { Name = FallbackConfigName };
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
}

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

var inheritingBranchConfig = GetBranchConfiguration(context, chosenBranch, excludedInheritBranches);
var configIncrement = inheritingBranchConfig.Increment;
if (inheritingBranchConfig.Name == FallbackConfigName && configIncrement == IncrementStrategy.Inherit)
{
Logger.WriteWarning("Fallback config inherits by default, dropping to patch increment");
configIncrement = IncrementStrategy.Patch;
}
return new BranchConfig(branchConfiguration)
{
Increment = inheritingBranchConfig.Increment,
Increment = configIncrement,
PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion,
// If we are inheriting from develop then we should behave like develop
TracksReleaseBranches = inheritingBranchConfig.TracksReleaseBranches
Expand Down