Skip to content

Commit 9c64e59

Browse files
committed
Add test for multiple branch config matches
This adds a test for validating that the first matched branch configuration will be chosen when multiple are present that match the current branch.
1 parent 881596b commit 9c64e59

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
9090
context.Configuration.Tag.ShouldBe("alpha");
9191
}
9292

93+
[Test]
94+
public void UsesFirstBranchConfigWhenMultipleMatch()
95+
{
96+
var config = new Config
97+
{
98+
VersioningMode = VersioningMode.ContinuousDelivery,
99+
Branches =
100+
{
101+
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest" } },
102+
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
103+
}
104+
}.ApplyDefaults();
105+
106+
var releaseLatestBranch = new MockBranch("release/latest") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
107+
var releaseVersionBranch = new MockBranch("release/1.0.0") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
108+
109+
var mockRepository = new MockRepository
110+
{
111+
Branches = new MockBranchCollection
112+
{
113+
releaseLatestBranch,
114+
releaseVersionBranch
115+
}
116+
};
117+
118+
var latestContext = new GitVersionContext(mockRepository, releaseLatestBranch, config);
119+
latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);
120+
121+
var versionContext = new GitVersionContext(mockRepository, releaseVersionBranch, config);
122+
versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
123+
}
124+
93125
[Test]
94126
public void CanFindParentBranchForInheritingIncrementStrategy()
95127
{

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IReposit
2020
if (matchingBranches.Length > 0)
2121
{
2222
branchConfiguration = matchingBranches[0];
23+
24+
if (matchingBranches.Length > 1) {
25+
Logger.WriteInfo(string.Format(
26+
"Multiple branch configurations match the current branch branchName of '{0}'. Using the first matching configuration, '{1}'. Matching configurations include: '{2}'",
27+
currentBranch.FriendlyName,
28+
branchConfiguration.Name,
29+
string.Join("', '", matchingBranches.Select(b => b.Name))));
30+
}
2331
}
2432
else
2533
{

0 commit comments

Comments
 (0)