Skip to content

Commit bcca05f

Browse files
committed
Moved defaulting config out of the ctor of Config class and into ConfigurationProvider
This allows a new empty instance of the config to be spun up. It also means all the defaulting logic and values are in a similar place rather than spread around the codebase
1 parent 27d0f8e commit bcca05f

15 files changed

+211
-114
lines changed
Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
assembly-versioning-scheme: MajorMinorPatch
2-
mode: ContinuousDelivery
3-
tag-prefix: '[vV]'
4-
continuous-delivery-fallback-tag: ci
5-
branches:
6-
master:
7-
tag:
8-
increment: Patch
9-
prevent-increment-of-merged-branch-version: true
10-
release[/-]:
11-
tag: beta
12-
feature[/-]:
13-
tag: useBranchName
14-
increment: Inherit
15-
hotfix[/-]:
16-
tag: beta
17-
support[/-]:
18-
tag:
19-
increment: Patch
20-
prevent-increment-of-merged-branch-version: true
21-
develop:
22-
mode: ContinuousDeployment
23-
tag: unstable
24-
increment: Minor
25-
track-merge-target: true
26-
(pull|pull\-requests|pr)[/-]:
27-
tag: PullRequest
28-
increment: Inherit
29-
tag-number-pattern: '[/-](?<number>\d+)[-/]'
1+
assembly-versioning-scheme: MajorMinorPatch
2+
mode: ContinuousDelivery
3+
tag-prefix: '[vV]'
4+
continuous-delivery-fallback-tag: ci
5+
branches:
6+
master:
7+
mode: ContinuousDelivery
8+
tag:
9+
increment: Patch
10+
prevent-increment-of-merged-branch-version: true
11+
track-merge-target: false
12+
release[/-]:
13+
mode: ContinuousDelivery
14+
tag: beta
15+
increment: Patch
16+
prevent-increment-of-merged-branch-version: true
17+
track-merge-target: false
18+
feature[/-]:
19+
mode: ContinuousDelivery
20+
tag: useBranchName
21+
increment: Inherit
22+
prevent-increment-of-merged-branch-version: false
23+
track-merge-target: false
24+
(pull|pull\-requests|pr)[/-]:
25+
mode: ContinuousDelivery
26+
tag: PullRequest
27+
increment: Inherit
28+
prevent-increment-of-merged-branch-version: false
29+
tag-number-pattern: '[/-](?<number>\d+)[-/]'
30+
track-merge-target: false
31+
hotfix[/-]:
32+
mode: ContinuousDelivery
33+
tag: beta
34+
increment: Patch
35+
prevent-increment-of-merged-branch-version: false
36+
track-merge-target: false
37+
support[/-]:
38+
mode: ContinuousDelivery
39+
tag:
40+
increment: Patch
41+
prevent-increment-of-merged-branch-version: true
42+
track-merge-target: false
43+
develop:
44+
mode: ContinuousDeployment
45+
tag: unstable
46+
increment: Minor
47+
prevent-increment-of-merged-branch-version: false
48+
track-merge-target: true

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class RepositoryFixtureBase : IDisposable
1616

1717
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config configuration)
1818
{
19+
ConfigurationProvider.ApplyDefaultsTo(configuration);
1920
diagramBuilder = new StringBuilder();
2021
diagramBuilder.AppendLine("@startuml");
2122
this.configuration = configuration;

src/GitVersionCore.Tests/GitVersionContextBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public GitVersionContextBuilder AddBranch(string branchName)
5858

5959
public GitVersionContext Build()
6060
{
61-
return new GitVersionContext(repository ?? CreateRepository(), config ?? new Config());
61+
var configuration = config ?? new Config();
62+
ConfigurationProvider.ApplyDefaultsTo(configuration);
63+
return new GitVersionContext(repository ?? CreateRepository(), configuration);
6264
}
6365

6466
IRepository CreateRepository()

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void CanInheritVersioningMode(VersioningMode mode)
1515
{
1616
VersioningMode = mode
1717
};
18+
ConfigurationProvider.ApplyDefaultsTo(config);
1819

1920
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
2021
var mockRepository = new MockRepository
@@ -34,10 +35,19 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
3435
{
3536
var config = new Config
3637
{
37-
VersioningMode = VersioningMode.ContinuousDelivery
38+
VersioningMode = VersioningMode.ContinuousDelivery,
39+
Branches =
40+
{
41+
{
42+
"develop", new BranchConfig
43+
{
44+
VersioningMode = VersioningMode.ContinuousDeployment,
45+
Tag = "alpha"
46+
}
47+
}
48+
}
3849
};
39-
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDeployment;
40-
config.Branches["develop"].Tag = "alpha";
50+
ConfigurationProvider.ApplyDefaultsTo(config);
4151
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
4252
var mockRepository = new MockRepository
4353
{
@@ -54,9 +64,14 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
5464
[Test]
5565
public void CanFindParentBranchForInheritingIncrementStrategy()
5666
{
57-
var config = new Config();
58-
config.Branches["develop"].Increment = IncrementStrategy.Major;
59-
config.Branches["feature[/-]"].Increment = IncrementStrategy.Inherit;
67+
var config = new Config
68+
{
69+
Branches =
70+
{
71+
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major} },
72+
{ "feature[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
73+
}
74+
};
6075

6176
using (var repo = new EmptyRepositoryFixture(config))
6277
{

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
5555
[Test]
5656
public void CanChangeDevelopTagViaConfig()
5757
{
58-
var config = new Config();
59-
config.Branches["develop"].Tag = "alpha";
58+
var config = new Config
59+
{
60+
Branches =
61+
{
62+
{ "develop", new BranchConfig { Tag = "alpha" } }
63+
}
64+
};
6065
using (var fixture = new EmptyRepositoryFixture(config))
6166
{
6267
fixture.Repository.MakeATaggedCommit("1.0.0");
@@ -100,8 +105,13 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel
100105
[Test]
101106
public void CanHandleContinuousDelivery()
102107
{
103-
var config = new Config();
104-
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery;
108+
var config = new Config
109+
{
110+
Branches =
111+
{
112+
{ "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery} }
113+
}
114+
};
105115
using (var fixture = new EmptyRepositoryFixture(config))
106116
{
107117
fixture.Repository.MakeATaggedCommit("1.0.0");

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ public void ShouldInheritIncrementCorrectlyWithMultiplePossibleParentsAndWeirdly
3535
[Test]
3636
public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
3737
{
38-
var config = new Config();
39-
config.Branches.Add("unstable", config.Branches["develop"]);
38+
var config = new Config
39+
{
40+
Branches =
41+
{
42+
{ "unstable", new BranchConfig { Increment = IncrementStrategy.Minor } }
43+
}
44+
};
4045

4146
using (var fixture = new EmptyRepositoryFixture(config))
4247
{

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ public void ReleaseBranchWithNextVersionSetInConfig()
8989
[Test]
9090
public void CanTakeVersionFromReleaseBranchWithTagOverridden()
9191
{
92-
var config = new Config();
93-
config.Branches["release[/-]"].Tag = "rc";
92+
var config = new Config
93+
{
94+
Branches =
95+
{
96+
{ "release[/-]", new BranchConfig { Tag = "rc" } }
97+
}
98+
};
9499
using (var fixture = new EmptyRepositoryFixture(config))
95100
{
96101
fixture.Repository.MakeATaggedCommit("1.0.3");

src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ public class VersionBumpingScenarios
77
[Test]
88
public void AppliedPrereleaseTagCausesBump()
99
{
10-
var configuration = new Config();
11-
configuration.Branches["master"].Tag = "pre";
10+
var configuration = new Config
11+
{
12+
Branches =
13+
{
14+
{ "master", new BranchConfig { Tag = "pre" } }
15+
}
16+
};
1217
using (var fixture = new EmptyRepositoryFixture(configuration))
1318
{
1419
fixture.Repository.MakeACommit();

src/GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class SemanticVersionTests
2626
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null)]
2727
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null)]
2828
[TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null, null)]
29-
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, Config.DefaultTagPrefix)]
30-
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", Config.DefaultTagPrefix)]
31-
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", Config.DefaultTagPrefix)]
29+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, ConfigurationProvider.DefaultTagPrefix)]
30+
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)]
31+
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)]
3232
[TestCase("version-1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", "version-")]
3333
public void ValidateVersionParsing(
3434
string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds,

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
1414

1515
if (matchingBranches.Length == 0)
1616
{
17-
return new KeyValuePair<string, BranchConfig>(string.Empty, new BranchConfig());
17+
var branchConfig = new BranchConfig();
18+
ConfigurationProvider.ApplyBranchDefaults(config, branchConfig);
19+
return new KeyValuePair<string, BranchConfig>(string.Empty, branchConfig);
1820
}
1921
if (matchingBranches.Length == 1)
2022
{

0 commit comments

Comments
 (0)