Skip to content

Commit 7dbed1e

Browse files
committed
introduce ConfigurationBuilder
1 parent 0678d55 commit 7dbed1e

File tree

15 files changed

+402
-385
lines changed

15 files changed

+402
-385
lines changed

src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
225225

226226
var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);
227227

228-
var config = DefaultConfigProvider.CreateDefaultConfig().Apply(new Config { TagPrefix = "prefix" }).FinalizeConfig();
228+
var config = new ConfigurationBuilder().Add(new Config { TagPrefix = "prefix" }).Build();
229229
gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath, ConfigInfo = { OverrideConfig = config } };
230230

231231
gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);

src/GitVersionCore.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
2121
{
2222
if (configuration == null)
2323
{
24-
configuration = DefaultConfigProvider.CreateDefaultConfig();
24+
configuration = new ConfigurationBuilder().Build();
2525
}
2626

2727
repository ??= fixture.Repository;
@@ -67,7 +67,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
6767
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
6868
{
6969
configuration ??= new Config();
70-
configuration = DefaultConfigProvider.CreateDefaultConfig().Apply(configuration).FinalizeConfig();
70+
configuration = new ConfigurationBuilder().Add(configuration).Build();
7171
Console.WriteLine("---------");
7272

7373
try

src/GitVersionCore.Tests/Helpers/GitVersionContextBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public void Build()
7777
{
7878
var repo = repository ?? CreateRepository();
7979

80-
var config = DefaultConfigProvider.CreateDefaultConfig()
81-
.Apply(configuration ?? new Config())
82-
.FinalizeConfig();
80+
var config = new ConfigurationBuilder()
81+
.Add(configuration ?? new Config())
82+
.Build();
8383

8484
var options = Options.Create(new GitVersionOptions
8585
{

src/GitVersionCore.Tests/Helpers/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected static IServiceProvider ConfigureServices(Action<IServiceCollection> o
2626

2727
protected static IServiceProvider BuildServiceProvider(string workingDirectory, IRepository repository, string branch, Config config = null)
2828
{
29-
config ??= DefaultConfigProvider.CreateDefaultConfig().FinalizeConfig();
29+
config ??= new ConfigurationBuilder().Build();
3030
var options = Options.Create(new GitVersionOptions
3131
{
3232
WorkingDirectory = workingDirectory,

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,21 @@ public void FeatureFromReleaseBranchShouldNotResetCount()
558558
[Test]
559559
public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
560560
{
561-
var config = DefaultConfigProvider.CreateDefaultConfig()
562-
.Apply(new Config
563-
{
564-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
565-
Branches =
566-
{
567-
{
568-
"release", new BranchConfig
569-
{
570-
PreReleaseWeight = 1000
571-
}
572-
}
573-
}
574-
})
575-
.FinalizeConfig();
561+
var config = new ConfigurationBuilder()
562+
.Add(new Config
563+
{
564+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
565+
Branches =
566+
{
567+
{
568+
"release", new BranchConfig
569+
{
570+
PreReleaseWeight = 1000
571+
}
572+
}
573+
}
574+
})
575+
.Build();
576576
using var fixture = new EmptyRepositoryFixture();
577577
fixture.Repository.MakeATaggedCommit("1.0.3");
578578
fixture.Repository.MakeCommits(5);
@@ -586,12 +586,12 @@ public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
586586
[Test]
587587
public void AssemblySemFileVerShouldBeWeightedByDefaultPreReleaseWeight()
588588
{
589-
var config = DefaultConfigProvider.CreateDefaultConfig()
590-
.Apply(new Config
591-
{
592-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
593-
})
594-
.FinalizeConfig();
589+
var config = new ConfigurationBuilder()
590+
.Add(new Config
591+
{
592+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
593+
})
594+
.Build();
595595

596596
using var fixture = new EmptyRepositoryFixture();
597597
fixture.Repository.MakeATaggedCommit("1.0.3");

src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class VersionInTagScenarios
1414
public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheDefaultValue()
1515
{
1616
// Arrange
17-
var config = DefaultConfigProvider.CreateDefaultConfig()
18-
.Apply(new Config
19-
{
20-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
21-
})
22-
.FinalizeConfig();
17+
var config = new ConfigurationBuilder()
18+
.Add(new Config
19+
{
20+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
21+
})
22+
.Build();
2323

2424
// Act
2525
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
@@ -34,13 +34,13 @@ public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreRe
3434
public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight()
3535
{
3636
// Arrange
37-
var config = DefaultConfigProvider.CreateDefaultConfig()
38-
.Apply(new Config
39-
{
40-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
41-
TagPreReleaseWeight = 65535
42-
})
43-
.FinalizeConfig();
37+
var config = new ConfigurationBuilder()
38+
.Add(new Config
39+
{
40+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
41+
TagPreReleaseWeight = 65535
42+
})
43+
.Build();
4444

4545
// Act
4646
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
@@ -55,14 +55,14 @@ public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreRelea
5555
public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight()
5656
{
5757
// Arrange
58-
var config = DefaultConfigProvider.CreateDefaultConfig()
59-
.Apply(new Config
60-
{
61-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
62-
TagPreReleaseWeight = 65535,
63-
VersioningMode = VersioningMode.ContinuousDeployment
64-
})
65-
.FinalizeConfig();
58+
var config = new ConfigurationBuilder()
59+
.Add(new Config
60+
{
61+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
62+
TagPreReleaseWeight = 65535,
63+
VersioningMode = VersioningMode.ContinuousDeployment
64+
})
65+
.Build();
6666

6767
// Act
6868
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
@@ -84,13 +84,13 @@ public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPre
8484
public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheDefaultValue()
8585
{
8686
// Arrange
87-
var config = DefaultConfigProvider.CreateDefaultConfig()
88-
.Apply(new Config
89-
{
90-
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
91-
VersioningMode = VersioningMode.ContinuousDeployment
92-
})
93-
.FinalizeConfig();
87+
var config = new ConfigurationBuilder()
88+
.Add(new Config
89+
{
90+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
91+
VersioningMode = VersioningMode.ContinuousDeployment
92+
})
93+
.Build();
9494

9595
// Act
9696
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");

src/GitVersionCore.Tests/Model/GitVersionContextTests.cs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ public void CanInheritVersioningMode(VersioningMode mode)
2323
{
2424
using var fixture = new EmptyRepositoryFixture();
2525

26-
var config = DefaultConfigProvider.CreateDefaultConfig()
27-
.Apply(new Config
28-
{
29-
VersioningMode = mode
30-
})
31-
.FinalizeConfig();
26+
var config = new ConfigurationBuilder()
27+
.Add(new Config { VersioningMode = mode })
28+
.Build();
3229

3330
var branchName = "master";
3431
var mockBranch = new MockBranch(branchName) { new MockCommit { CommitterEx = Generate.SignatureNow() } };
@@ -56,9 +53,9 @@ public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy?
5653
// Dummy branch name to make sure that no default config exists.
5754
const string dummyBranchName = "dummy";
5855

59-
var config = DefaultConfigProvider.CreateDefaultConfig()
60-
.Apply(new Config { Increment = increment })
61-
.FinalizeConfig();
56+
var config = new ConfigurationBuilder()
57+
.Add(new Config { Increment = increment })
58+
.Build();
6259

6360
using var fixture = new EmptyRepositoryFixture();
6461
fixture.MakeACommit();
@@ -76,22 +73,22 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
7673
using var fixture = new EmptyRepositoryFixture();
7774

7875
var branchName = "develop";
79-
var config = DefaultConfigProvider.CreateDefaultConfig()
80-
.Apply(new Config
81-
{
82-
VersioningMode = VersioningMode.ContinuousDelivery,
83-
Branches =
84-
{
76+
var config = new ConfigurationBuilder()
77+
.Add(new Config
78+
{
79+
VersioningMode = VersioningMode.ContinuousDelivery,
80+
Branches =
81+
{
82+
{
83+
branchName, new BranchConfig
8584
{
86-
branchName, new BranchConfig
87-
{
88-
VersioningMode = VersioningMode.ContinuousDeployment,
89-
Tag = "alpha"
90-
}
85+
VersioningMode = VersioningMode.ContinuousDeployment,
86+
Tag = "alpha"
9187
}
92-
}
93-
})
94-
.FinalizeConfig();
88+
}
89+
}
90+
})
91+
.Build();
9592

9693
var develop = new MockBranch(branchName) { new MockCommit { CommitterEx = Generate.SignatureNow() } };
9794
var mockRepository = new MockRepository
@@ -124,17 +121,17 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
124121
IsReleaseBranch = false,
125122
SourceBranches = new HashSet<string>()
126123
};
127-
var config = DefaultConfigProvider.CreateDefaultConfig()
128-
.Apply(new Config
129-
{
130-
VersioningMode = VersioningMode.ContinuousDelivery,
131-
Branches =
132-
{
133-
{ "release/latest", new BranchConfig(branchConfig) { Increment = IncrementStrategy.None, Regex = "release/latest" } },
134-
{ "release", new BranchConfig(branchConfig) { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
135-
}
136-
})
137-
.FinalizeConfig();
124+
var config = new ConfigurationBuilder()
125+
.Add(new Config
126+
{
127+
VersioningMode = VersioningMode.ContinuousDelivery,
128+
Branches =
129+
{
130+
{ "release/latest", new BranchConfig(branchConfig) { Increment = IncrementStrategy.None, Regex = "release/latest" } },
131+
{ "release", new BranchConfig(branchConfig) { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
132+
}
133+
})
134+
.Build();
138135

139136
var releaseLatestBranch = new MockBranch("release/latest") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
140137
var releaseVersionBranch = new MockBranch("release/1.0.0") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
@@ -160,16 +157,16 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
160157
[Test]
161158
public void CanFindParentBranchForInheritingIncrementStrategy()
162159
{
163-
var config = DefaultConfigProvider.CreateDefaultConfig()
164-
.Apply(new Config
165-
{
166-
Branches =
167-
{
168-
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major } },
169-
{ "feature", new BranchConfig { Increment = IncrementStrategy.Inherit } }
170-
}
171-
})
172-
.FinalizeConfig();
160+
var config = new ConfigurationBuilder()
161+
.Add(new Config
162+
{
163+
Branches =
164+
{
165+
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major } },
166+
{ "feature", new BranchConfig { Increment = IncrementStrategy.Inherit } }
167+
}
168+
})
169+
.Build();
173170

174171
using var fixture = new EmptyRepositoryFixture();
175172
fixture.Repository.MakeACommit();

src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
5252
fixture.Repository.MakeACommit();
5353
fixture.Repository.CreateBranch(branchName);
5454

55-
var config = DefaultConfigProvider.CreateDefaultConfig()
56-
.Apply(new Config { Branches = { { "support", new BranchConfig { IsReleaseBranch = true } } } })
57-
.FinalizeConfig();
55+
var config = new ConfigurationBuilder()
56+
.Add(new Config { Branches = { { "support", new BranchConfig { IsReleaseBranch = true } } } })
57+
.Build();
5858

5959
var strategy = GetVersionStrategy(fixture.RepositoryPath, fixture.Repository, branchName, config);
6060

0 commit comments

Comments
 (0)