Skip to content

Use the first matched branch configuration #1070

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 3 commits into from
Nov 27, 2016
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
32 changes: 32 additions & 0 deletions src/GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
context.Configuration.Tag.ShouldBe("alpha");
}

[Test]
public void UsesFirstBranchConfigWhenMultipleMatch()
{
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDelivery,
Branches =
{
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest" } },
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
}
}.ApplyDefaults();

var releaseLatestBranch = new MockBranch("release/latest") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
var releaseVersionBranch = new MockBranch("release/1.0.0") { new MockCommit { CommitterEx = Generate.SignatureNow() } };

var mockRepository = new MockRepository
{
Branches = new MockBranchCollection
{
releaseLatestBranch,
releaseVersionBranch
}
};

var latestContext = new GitVersionContext(mockRepository, releaseLatestBranch, config);
latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);

var versionContext = new GitVersionContext(mockRepository, releaseVersionBranch, config);
versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
}

[Test]
public void CanFindParentBranchForInheritingIncrementStrategy()
{
Expand Down
17 changes: 10 additions & 7 deletions src/GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
{
var matchingBranches = LookupBranchConfiguration(config, currentBranch).ToArray();

if (matchingBranches.Length > 1)
{
const string format = "Multiple branch configurations match the current branch branchName of '{0}'. Matching configurations: '{1}'";
throw new Exception(string.Format(format, currentBranch.FriendlyName, string.Join(", ", matchingBranches.Select(b => b.Name))));
}

BranchConfig branchConfiguration;
if (matchingBranches.Length == 1)
if (matchingBranches.Length > 0)
{
branchConfiguration = matchingBranches[0];

if (matchingBranches.Length > 1)
{
Logger.WriteWarning(string.Format(
"Multiple branch configurations match the current branch branchName of '{0}'. Using the first matching configuration, '{1}'. Matching configurations include: '{2}'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be a warning..

currentBranch.FriendlyName,
branchConfiguration.Name,
string.Join("', '", matchingBranches.Select(b => b.Name))));
}
}
else
{
Expand Down