From 26f85a0b3bfc1f93bdc748299a9676fc7b834f85 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 4 Dec 2017 18:20:42 +0800 Subject: [PATCH 1/3] Should use targetBranch.Tip instead of CurrentCommit to give merge commit PRs a better chance of resolving --- src/GitVersionCore/BranchConfigurationCalculator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index 35215d5a42..3188181be6 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -65,7 +65,7 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch List 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) From 4b8cb311b41967d13f57e276007e8ed9785177da Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 4 Dec 2017 18:21:25 +0800 Subject: [PATCH 2/3] There is a scenario where no config is resolved during branch inheirtance, this falls back to default config, which is inherit. This causes infinite recursion. This fixes #1195 --- src/GitVersionCore/Configuration/ConfigurationProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index b72cd9ff3c..4fa320dd83 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -30,7 +30,7 @@ public class ConfigurationProvider public const string SupportBranchKey = "support"; public const string DevelopBranchKey = "develop"; - private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Inherit; + private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Patch; public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) { From 4c5d53e40a58f40480651034bcf4b2f96485bcfa Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Tue, 5 Dec 2017 22:30:02 +0800 Subject: [PATCH 3/3] Better more targeted fix --- src/GitVersionCore/BranchConfigurationCalculator.cs | 12 ++++++++++-- .../Configuration/ConfigurationProvider.cs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index 3188181be6..471f8560e8 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -8,6 +8,8 @@ namespace GitVersion public class BranchConfigurationCalculator { + public static string FallbackConfigName = "Fallback"; + /// /// Gets the for the current commit. /// @@ -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()); } @@ -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 diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index 4fa320dd83..b72cd9ff3c 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -30,7 +30,7 @@ public class ConfigurationProvider public const string SupportBranchKey = "support"; public const string DevelopBranchKey = "develop"; - private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Patch; + private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Inherit; public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) {