diff --git a/src/GitVersionCore.Tests/GitVersionContextTests.cs b/src/GitVersionCore.Tests/GitVersionContextTests.cs index d91910af75..5261f4a416 100644 --- a/src/GitVersionCore.Tests/GitVersionContextTests.cs +++ b/src/GitVersionCore.Tests/GitVersionContextTests.cs @@ -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() { diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index 5409bebd8f..14f314cf94 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -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}'", + currentBranch.FriendlyName, + branchConfiguration.Name, + string.Join("', '", matchingBranches.Select(b => b.Name)))); + } } else {