From c96d67b319915670fbdcbf94931b187bc9440fd7 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 8 Feb 2021 11:44:35 +0100 Subject: [PATCH 1/2] GH-2587 - fix source branch for master --- .../Configuration/ConfigurationBuilder.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs index f208653930..2db8a531b9 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs @@ -97,6 +97,11 @@ private static void ApplyBranchOverrides(Config targetConfig, Config overrideCon } branchConfig.MergeTo(target); + if (target.SourceBranches != null && target.SourceBranches.Contains(Config.MasterBranchKey)) + { + target.SourceBranches.Remove(Config.MasterBranchKey); + target.SourceBranches.Add(Config.MainBranchKey); + } newBranches[branchName] = target; } @@ -155,20 +160,22 @@ private static void ValidateConfiguration(Config config) foreach (var (name, branchConfig) in config.Branches) { var regex = branchConfig.Regex; + var helpUrl = $"{System.Environment.NewLine}See https://gitversion.net/docs/configuration for more info"; + if (regex == null) { - throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'regex'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration for more info"); + throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'regex'{helpUrl}"); } var sourceBranches = branchConfig.SourceBranches; if (sourceBranches == null) { - throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'source-branches'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration for more info"); + throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'source-branches'{helpUrl}"); } var missingSourceBranches = sourceBranches.Where(sb => !config.Branches.ContainsKey(sb)).ToArray(); if (missingSourceBranches.Any()) - throw new ConfigurationException($"Branch configuration '{name}' defines these 'source-branches' that are not configured: '[{string.Join(",", missingSourceBranches)}]'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration for more info"); + throw new ConfigurationException($"Branch configuration '{name}' defines these 'source-branches' that are not configured: '[{string.Join(",", missingSourceBranches)}]'{helpUrl}"); } } From eed614f44d268f09696610b8f6595aab1d1735a9 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 8 Feb 2021 11:31:05 +0100 Subject: [PATCH 2/2] GH-2587 - added tests to test the 'master' branch name replaced with 'main' --- .../Configuration/ConfigProviderTests.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs index 006d39326c..84474d4418 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs @@ -164,6 +164,44 @@ public void CanProvideConfigForNewBranch() config.Branches["bug"].Tag.ShouldBe("bugfix"); } + [Test] + public void MasterConfigReplacedWithMain() + { + const string text = @" +next-version: 2.0.0 +branches: + master: + regex: '^master$|^main$' + tag: beta"; + SetupConfigFileContent(text); + + var config = configProvider.Provide(repoPath); + + config.Branches[MainBranch].Regex.ShouldBe("^master$|^main$"); + config.Branches[MainBranch].Tag.ShouldBe("beta"); + } + + [Test] + public void MasterConfigReplacedWithMainInSourceBranches() + { + const string text = @" +next-version: 2.0.0 +branches: + breaking: + regex: breaking[/] + mode: ContinuousDeployment + increment: Major + source-branches: ['master'] + is-release-branch: false"; + SetupConfigFileContent(text); + + var config = configProvider.Provide(repoPath); + + config.Branches["breaking"].Regex.ShouldBe("breaking[/]"); + config.Branches["breaking"].SourceBranches.ShouldHaveSingleItem(); + config.Branches["breaking"].SourceBranches.ShouldContain(MainBranch); + } + [Test] public void NextVersionCanBeInteger() {