Skip to content

Commit 5aeca26

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 7523043 commit 5aeca26

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/GitVersionCore.Tests/GitVersionContextTests.cs

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

65+
[Test]
66+
public void UsesFirstBranchConfigWhenMultipleMatch()
67+
{
68+
var config = new Config
69+
{
70+
VersioningMode = VersioningMode.ContinuousDelivery,
71+
Branches =
72+
{
73+
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest" } },
74+
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
75+
}
76+
}.ApplyDefaults();
77+
78+
var releaseLatestBranch = new MockBranch("release/latest") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
79+
var releaseVersionBranch = new MockBranch("release/1.0.0") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
80+
81+
var mockRepository = new MockRepository
82+
{
83+
Branches = new MockBranchCollection
84+
{
85+
releaseLatestBranch,
86+
releaseVersionBranch
87+
}
88+
};
89+
90+
var latestContext = new GitVersionContext(mockRepository, releaseLatestBranch, config);
91+
latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);
92+
93+
var versionContext = new GitVersionContext(mockRepository, releaseVersionBranch, config);
94+
versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
95+
}
96+
6597
[Test]
6698
public void CanFindParentBranchForInheritingIncrementStrategy()
6799
{

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
3030
var keyValuePair = matchingBranches[0];
3131
var branchConfiguration = keyValuePair.Value;
3232

33+
if (matchingBranches.Length > 1)
34+
{
35+
Logger.WriteInfo(string.Format(
36+
"Multiple branch configurations match the current branch branchName of '{0}'. Using the first matching configuration, '{1}'. Matching configurations include: '{2}'",
37+
currentBranch.FriendlyName,
38+
keyValuePair.Key,
39+
string.Join("', '", matchingBranches.Select(b => b.Key))));
40+
}
41+
3342
if (branchConfiguration.Increment == IncrementStrategy.Inherit)
3443
{
3544
return InheritBranchConfiguration(onlyEvaluateTrackedBranches, repository, currentCommit, currentBranch, keyValuePair, branchConfiguration, config, excludedInheritBranches);

0 commit comments

Comments
 (0)