Skip to content

Commit

Permalink
Merge pull request #1336 from JakeGinnivan/fix/PossibleInfiniteInherit
Browse files Browse the repository at this point in the history
Fix/possible infinite inherit
  • Loading branch information
JakeGinnivan authored Dec 5, 2017
2 parents e51c088 + 4c5d53e commit 0f7e7b3
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit 0f7e7b3

Please sign in to comment.