Skip to content

Commit 4c945f4

Browse files
authored
Merge pull request #2300 from Inok/refactor-configuration
Refactor configuration
2 parents 3fccbc3 + 7dbed1e commit 4c945f4

37 files changed

+563
-450
lines changed

src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitVersion.BuildAgents;
88
using GitVersion.Configuration;
99
using GitVersion.Logging;
10+
using GitVersion.Model.Configuration;
1011
using GitVersion.VersionCalculation.Cache;
1112
using GitVersionCore.Tests.Helpers;
1213
using LibGit2Sharp;
@@ -224,8 +225,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
224225

225226
var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);
226227

227-
var config = new TestableConfig { TagPrefix = "prefix" };
228-
config.Reset();
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/Core/RepositoryExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using GitVersion.Logging;
1+
using System;
2+
using System.Collections.Generic;
3+
using GitVersion;
24
using GitVersion.Extensions;
5+
using GitVersion.Logging;
36
using GitVersionCore.Tests.Helpers;
47
using LibGit2Sharp;
5-
using NUnit.Framework;
68
using NSubstitute;
7-
using System;
8-
using System.Collections.Generic;
9-
using GitVersion;
9+
using NUnit.Framework;
1010

1111
namespace GitVersionCore.Tests
1212
{

src/GitVersionCore.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
2121
{
2222
if (configuration == null)
2323
{
24-
configuration = new TestableConfig();
25-
configuration.Reset();
24+
configuration = new ConfigurationBuilder().Build();
2625
}
2726

2827
repository ??= fixture.Repository;
@@ -67,8 +66,8 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
6766

6867
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
6968
{
70-
configuration ??= new TestableConfig();
71-
configuration.Reset();
69+
configuration ??= new Config();
70+
configuration = new ConfigurationBuilder().Add(configuration).Build();
7271
Console.WriteLine("---------");
7372

7473
try

src/GitVersionCore.Tests/Helpers/GitVersionContextBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ private GitVersionContextBuilder AddBranch(string branchName)
7676
public void Build()
7777
{
7878
var repo = repository ?? CreateRepository();
79-
var config = configuration ?? new TestableConfig();
8079

81-
config.Reset();
80+
var config = new ConfigurationBuilder()
81+
.Add(configuration ?? new Config())
82+
.Build();
8283

8384
var options = Options.Create(new GitVersionOptions
8485
{

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 ??= new TestableConfig().ApplyDefaults();
29+
config ??= new ConfigurationBuilder().Build();
3030
var options = Options.Create(new GitVersionOptions
3131
{
3232
WorkingDirectory = workingDirectory,

src/GitVersionCore.Tests/Helpers/TestableConfig.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
5555
[Test]
5656
public void CanChangeDevelopTagViaConfig()
5757
{
58-
var config = new TestableConfig
58+
var config = new Config
5959
{
6060
Branches =
6161
{
6262
{
63-
"develop", new BranchConfig
63+
"develop",
64+
new BranchConfig
6465
{
6566
Tag = "alpha",
66-
SourceBranches = new List<string>()
67+
SourceBranches = new HashSet<string>()
6768
}
6869
}
6970
}
@@ -115,16 +116,9 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMasterDoesBumpDevelo
115116
[Test]
116117
public void CanHandleContinuousDelivery()
117118
{
118-
var config = new TestableConfig
119+
var config = new Config
119120
{
120-
Branches =
121-
{
122-
{"develop", new BranchConfig
123-
{
124-
VersioningMode = VersioningMode.ContinuousDelivery
125-
}
126-
}
127-
}
121+
Branches = { { "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery } } }
128122
};
129123
using var fixture = new EmptyRepositoryFixture();
130124
fixture.Repository.MakeATaggedCommit("1.0.0");
@@ -205,7 +199,7 @@ public void TagOnHotfixShouldNotAffectDevelop()
205199
[Test]
206200
public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
207201
{
208-
var config = new TestableConfig
202+
var config = new Config
209203
{
210204
VersioningMode = VersioningMode.ContinuousDeployment
211205
};
@@ -246,7 +240,7 @@ public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
246240
[Test]
247241
public void CommitsSinceVersionSourceShouldNotGoDownUponMergingFeatureOnlyToDevelop()
248242
{
249-
var config = new TestableConfig
243+
var config = new Config
250244
{
251245
VersioningMode = VersioningMode.ContinuousDeployment
252246
};

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void ShouldInheritIncrementCorrectlyWithMultiplePossibleParentsAndWeirdly
4141
[Test]
4242
public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
4343
{
44-
var config = new TestableConfig
44+
var config = new Config
4545
{
4646
Branches =
4747
{
@@ -51,8 +51,8 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
5151
{
5252
Increment = IncrementStrategy.Minor,
5353
Regex = "unstable",
54-
SourceBranches = new List<string>(),
55-
IsSourceBranchFor = new [] { "feature" }
54+
SourceBranches = new HashSet<string>(),
55+
IsSourceBranchFor = new HashSet<string> { "feature" }
5656
}
5757
}
5858
}
@@ -169,14 +169,14 @@ public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMa
169169
Commands.Checkout(fixture.Repository, "feature/longrunning");
170170
fixture.Repository.Merge(fixture.Repository.Branches["develop"], Generate.SignatureNow());
171171

172-
var configuration = new TestableConfig { VersioningMode = VersioningMode.ContinuousDeployment };
172+
var configuration = new Config { VersioningMode = VersioningMode.ContinuousDeployment };
173173
fixture.AssertFullSemver("1.2.0-longrunning.2", configuration);
174174
}
175175

176176
[Test]
177177
public void CanUseBranchNameOffAReleaseBranch()
178178
{
179-
var config = new TestableConfig
179+
var config = new Config
180180
{
181181
Branches =
182182
{
@@ -201,7 +201,7 @@ public void CanUseBranchNameOffAReleaseBranch()
201201
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
202202
public void ShouldUseConfiguredTag(string tag, string featureName, string preReleaseTagName)
203203
{
204-
var config = new TestableConfig
204+
var config = new Config
205205
{
206206
Branches =
207207
{
@@ -301,7 +301,7 @@ public class WhenMasterMarkedAsIsDevelop
301301
[Test]
302302
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
303303
{
304-
var config = new TestableConfig
304+
var config = new Config
305305
{
306306
Branches = new Dictionary<string, BranchConfig>
307307
{
@@ -332,7 +332,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
332332
[Test]
333333
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
334334
{
335-
var config = new TestableConfig
335+
var config = new Config
336336
{
337337
Branches = new Dictionary<string, BranchConfig>
338338
{
@@ -411,7 +411,7 @@ public class WhenMasterMarkedAsIsDevelop
411411
[Test]
412412
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
413413
{
414-
var config = new TestableConfig
414+
var config = new Config
415415
{
416416
Branches = new Dictionary<string, BranchConfig>
417417
{
@@ -442,7 +442,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
442442
[Test]
443443
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
444444
{
445-
var config = new TestableConfig
445+
var config = new Config
446446
{
447447
Branches = new Dictionary<string, BranchConfig>
448448
{
@@ -477,7 +477,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
477477
[Test]
478478
public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
479479
{
480-
var config = new TestableConfig
480+
var config = new Config
481481
{
482482
VersioningMode = VersioningMode.ContinuousDelivery,
483483
Branches = new Dictionary<string, BranchConfig>
@@ -521,7 +521,7 @@ public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
521521
[Test]
522522
public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature()
523523
{
524-
var config = new TestableConfig
524+
var config = new Config
525525
{
526526
VersioningMode = VersioningMode.ContinuousDeployment,
527527
AssemblyVersioningScheme = AssemblyVersioningScheme.Major,

src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using GitTools.Testing;
33
using GitVersion.Extensions;
4+
using GitVersion.Model.Configuration;
45
using GitVersion.VersionCalculation;
56
using GitVersionCore.Tests.Helpers;
67
using LibGit2Sharp;
@@ -127,7 +128,7 @@ public void PatchOlderReleaseExample()
127128
[Test]
128129
public void FeatureOnHotfixFeatureBranchDeleted()
129130
{
130-
var config = new TestableConfig
131+
var config = new Config
131132
{
132133
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
133134
VersioningMode = VersioningMode.ContinuousDeployment
@@ -180,7 +181,7 @@ public void FeatureOnHotfixFeatureBranchDeleted()
180181
[Test]
181182
public void FeatureOnHotfixFeatureBranchNotDeleted()
182183
{
183-
var config = new TestableConfig
184+
var config = new Config
184185
{
185186
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
186187
VersioningMode = VersioningMode.ContinuousDeployment

src/GitVersionCore.Tests/IntegrationTests/MainlineDevelopmentMode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace GitVersionCore.Tests.IntegrationTests
1515
{
1616
public class MainlineDevelopmentMode : TestBase
1717
{
18-
private readonly Config config = new TestableConfig
18+
private readonly Config config = new Config
1919
{
2020
VersioningMode = VersioningMode.Mainline
2121
};
@@ -397,7 +397,7 @@ public void VerifyMergingMasterIntoAFeatureBranchWorksWithMultipleBranches()
397397
[Test]
398398
public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionOfMaster()
399399
{
400-
var currentConfig = new TestableConfig
400+
var currentConfig = new Config
401401
{
402402
VersioningMode = VersioningMode.Mainline,
403403
Branches = new Dictionary<string, BranchConfig>
@@ -430,7 +430,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO
430430
[Test]
431431
public void VerifyIncrementConfigIsHonoured()
432432
{
433-
var minorIncrementConfig = new TestableConfig
433+
var minorIncrementConfig = new Config
434434
{
435435
VersioningMode = VersioningMode.Mainline,
436436
Increment = IncrementStrategy.Minor,

src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class MasterScenarios : TestBase
1313
[Test]
1414
public void CanHandleContinuousDelivery()
1515
{
16-
var config = new TestableConfig
16+
var config = new Config
1717
{
1818
Branches =
1919
{
@@ -34,7 +34,7 @@ public void CanHandleContinuousDelivery()
3434
[Test]
3535
public void CanHandleContinuousDeployment()
3636
{
37-
var config = new TestableConfig
37+
var config = new Config
3838
{
3939
Branches =
4040
{
@@ -100,7 +100,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0
100100
public void GivenARepositoryWithTagAndNextVersionInConfigVersionShouldMatchVersionTxtFile()
101101
{
102102
const string expectedNextVersion = "1.1.0";
103-
var config = new TestableConfig { NextVersion = expectedNextVersion };
103+
var config = new Config { NextVersion = expectedNextVersion };
104104
using var fixture = new EmptyRepositoryFixture();
105105
const string taggedVersion = "1.0.3";
106106
fixture.Repository.MakeATaggedCommit(taggedVersion);
@@ -116,7 +116,7 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou
116116
const string taggedVersion = "1.0.3";
117117
fixture.Repository.MakeATaggedCommit(taggedVersion);
118118

119-
fixture.AssertFullSemver("1.0.3", new TestableConfig { NextVersion = "1.1.0" });
119+
fixture.AssertFullSemver("1.0.3", new Config { NextVersion = "1.1.0" });
120120
}
121121

122122
[Test]
@@ -148,7 +148,7 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigVersionShouldBeTagWith
148148
fixture.Repository.MakeATaggedCommit(taggedVersion);
149149
fixture.Repository.MakeCommits(5);
150150

151-
fixture.AssertFullSemver("1.1.1+5", new TestableConfig { NextVersion = "1.0.0" });
151+
fixture.AssertFullSemver("1.1.1+5", new Config { NextVersion = "1.0.0" });
152152
}
153153

154154
[Test]
@@ -158,7 +158,7 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigAndNoCommitsVersionSho
158158
const string taggedVersion = "1.1.0";
159159
fixture.Repository.MakeATaggedCommit(taggedVersion);
160160

161-
fixture.AssertFullSemver("1.1.0", new TestableConfig { NextVersion = "1.0.0" });
161+
fixture.AssertFullSemver("1.1.0", new Config { NextVersion = "1.0.0" });
162162
}
163163

164164
[Test]
@@ -169,13 +169,13 @@ public void CanSpecifyTagPrefixes()
169169
fixture.Repository.MakeATaggedCommit(taggedVersion);
170170
fixture.Repository.MakeCommits(5);
171171

172-
fixture.AssertFullSemver("1.0.4+5", new TestableConfig { TagPrefix = "version-" });
172+
fixture.AssertFullSemver("1.0.4+5", new Config { TagPrefix = "version-" });
173173
}
174174

175175
[Test]
176176
public void CanSpecifyTagPrefixesAsRegex()
177177
{
178-
var config = new TestableConfig { TagPrefix = "version-|[vV]" };
178+
var config = new Config { TagPrefix = "version-|[vV]" };
179179
using var fixture = new EmptyRepositoryFixture();
180180
var taggedVersion = "v1.0.3";
181181
fixture.Repository.MakeATaggedCommit(taggedVersion);
@@ -193,7 +193,7 @@ public void CanSpecifyTagPrefixesAsRegex()
193193
[Test]
194194
public void AreTagsNotAdheringToTagPrefixIgnored()
195195
{
196-
var config = new TestableConfig { TagPrefix = "" };
196+
var config = new Config { TagPrefix = "" };
197197
using var fixture = new EmptyRepositoryFixture();
198198
var taggedVersion = "version-1.0.3";
199199
fixture.Repository.MakeATaggedCommit(taggedVersion);

0 commit comments

Comments
 (0)