Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
13 changes: 10 additions & 3 deletions src/GitVersion.Core/Configuration/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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}");
}
}

Expand Down