Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor configuration #2300

Merged
merged 8 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GitVersion.BuildAgents;
using GitVersion.Configuration;
using GitVersion.Logging;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation.Cache;
using GitVersionCore.Tests.Helpers;
using LibGit2Sharp;
Expand Down Expand Up @@ -224,8 +225,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn

var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);

var config = new TestableConfig { TagPrefix = "prefix" };
config.Reset();
var config = DefaultConfigProvider.CreateDefaultConfig().Apply(new Config { TagPrefix = "prefix" }).FinalizeConfig();
gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath, ConfigInfo = { OverrideConfig = config } };

gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
Expand Down
10 changes: 5 additions & 5 deletions src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using GitVersion.Logging;
using System;
using System.Collections.Generic;
using GitVersion;
using GitVersion.Extensions;
using GitVersion.Logging;
using GitVersionCore.Tests.Helpers;
using LibGit2Sharp;
using NUnit.Framework;
using NSubstitute;
using System;
using System.Collections.Generic;
using GitVersion;
using NUnit.Framework;

namespace GitVersionCore.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
{
if (configuration == null)
{
configuration = new TestableConfig();
configuration.Reset();
configuration = DefaultConfigProvider.CreateDefaultConfig();
}

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

public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
{
configuration ??= new TestableConfig();
configuration.Reset();
configuration ??= new Config();
configuration = DefaultConfigProvider.CreateDefaultConfig().Apply(configuration).FinalizeConfig();
Console.WriteLine("---------");

try
Expand Down
5 changes: 3 additions & 2 deletions src/GitVersionCore.Tests/Helpers/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ private GitVersionContextBuilder AddBranch(string branchName)
public void Build()
{
var repo = repository ?? CreateRepository();
var config = configuration ?? new TestableConfig();

config.Reset();
var config = DefaultConfigProvider.CreateDefaultConfig()
.Apply(configuration ?? new Config())
.FinalizeConfig();

var options = Options.Create(new GitVersionOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/Helpers/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected static IServiceProvider ConfigureServices(Action<IServiceCollection> o

protected static IServiceProvider BuildServiceProvider(string workingDirectory, IRepository repository, string branch, Config config = null)
{
config ??= new TestableConfig().ApplyDefaults();
config ??= DefaultConfigProvider.CreateDefaultConfig().FinalizeConfig();
var options = Options.Create(new GitVersionOptions
{
WorkingDirectory = workingDirectory,
Expand Down
24 changes: 0 additions & 24 deletions src/GitVersionCore.Tests/Helpers/TestableConfig.cs

This file was deleted.

22 changes: 8 additions & 14 deletions src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
[Test]
public void CanChangeDevelopTagViaConfig()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
{
"develop", new BranchConfig
"develop",
new BranchConfig
{
Tag = "alpha",
SourceBranches = new List<string>()
SourceBranches = new HashSet<string>()
}
}
}
Expand Down Expand Up @@ -115,16 +116,9 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMasterDoesBumpDevelo
[Test]
public void CanHandleContinuousDelivery()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
{"develop", new BranchConfig
{
VersioningMode = VersioningMode.ContinuousDelivery
}
}
}
Branches = { { "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery } } }
};
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0.0");
Expand Down Expand Up @@ -205,7 +199,7 @@ public void TagOnHotfixShouldNotAffectDevelop()
[Test]
public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
{
var config = new TestableConfig
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDeployment
};
Expand Down Expand Up @@ -246,7 +240,7 @@ public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
[Test]
public void CommitsSinceVersionSourceShouldNotGoDownUponMergingFeatureOnlyToDevelop()
{
var config = new TestableConfig
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDeployment
};
Expand Down
24 changes: 12 additions & 12 deletions src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void ShouldInheritIncrementCorrectlyWithMultiplePossibleParentsAndWeirdly
[Test]
public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
Expand All @@ -51,8 +51,8 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
{
Increment = IncrementStrategy.Minor,
Regex = "unstable",
SourceBranches = new List<string>(),
IsSourceBranchFor = new [] { "feature" }
SourceBranches = new HashSet<string>(),
IsSourceBranchFor = new HashSet<string> { "feature" }
}
}
}
Expand Down Expand Up @@ -169,14 +169,14 @@ public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMa
Commands.Checkout(fixture.Repository, "feature/longrunning");
fixture.Repository.Merge(fixture.Repository.Branches["develop"], Generate.SignatureNow());

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

[Test]
public void CanUseBranchNameOffAReleaseBranch()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
Expand All @@ -201,7 +201,7 @@ public void CanUseBranchNameOffAReleaseBranch()
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
public void ShouldUseConfiguredTag(string tag, string featureName, string preReleaseTagName)
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public class WhenMasterMarkedAsIsDevelop
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new TestableConfig
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -332,7 +332,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new TestableConfig
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -411,7 +411,7 @@ public class WhenMasterMarkedAsIsDevelop
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new TestableConfig
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -442,7 +442,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new TestableConfig
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -477,7 +477,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
[Test]
public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
{
var config = new TestableConfig
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDelivery,
Branches = new Dictionary<string, BranchConfig>
Expand Down Expand Up @@ -521,7 +521,7 @@ public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
[Test]
public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature()
{
var config = new TestableConfig
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDeployment,
AssemblyVersioningScheme = AssemblyVersioningScheme.Major,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using GitTools.Testing;
using GitVersion.Extensions;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using LibGit2Sharp;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void PatchOlderReleaseExample()
[Test]
public void FeatureOnHotfixFeatureBranchDeleted()
{
var config = new TestableConfig
var config = new Config
{
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
VersioningMode = VersioningMode.ContinuousDeployment
Expand Down Expand Up @@ -180,7 +181,7 @@ public void FeatureOnHotfixFeatureBranchDeleted()
[Test]
public void FeatureOnHotfixFeatureBranchNotDeleted()
{
var config = new TestableConfig
var config = new Config
{
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
VersioningMode = VersioningMode.ContinuousDeployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace GitVersionCore.Tests.IntegrationTests
{
public class MainlineDevelopmentMode : TestBase
{
private readonly Config config = new TestableConfig
private readonly Config config = new Config
{
VersioningMode = VersioningMode.Mainline
};
Expand Down Expand Up @@ -397,7 +397,7 @@ public void VerifyMergingMasterIntoAFeatureBranchWorksWithMultipleBranches()
[Test]
public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionOfMaster()
{
var currentConfig = new TestableConfig
var currentConfig = new Config
{
VersioningMode = VersioningMode.Mainline,
Branches = new Dictionary<string, BranchConfig>
Expand Down Expand Up @@ -430,7 +430,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO
[Test]
public void VerifyIncrementConfigIsHonoured()
{
var minorIncrementConfig = new TestableConfig
var minorIncrementConfig = new Config
{
VersioningMode = VersioningMode.Mainline,
Increment = IncrementStrategy.Minor,
Expand Down
18 changes: 9 additions & 9 deletions src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MasterScenarios : TestBase
[Test]
public void CanHandleContinuousDelivery()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
Expand All @@ -34,7 +34,7 @@ public void CanHandleContinuousDelivery()
[Test]
public void CanHandleContinuousDeployment()
{
var config = new TestableConfig
var config = new Config
{
Branches =
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0
public void GivenARepositoryWithTagAndNextVersionInConfigVersionShouldMatchVersionTxtFile()
{
const string expectedNextVersion = "1.1.0";
var config = new TestableConfig { NextVersion = expectedNextVersion };
var config = new Config { NextVersion = expectedNextVersion };
using var fixture = new EmptyRepositoryFixture();
const string taggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
Expand All @@ -116,7 +116,7 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou
const string taggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);

fixture.AssertFullSemver("1.0.3", new TestableConfig { NextVersion = "1.1.0" });
fixture.AssertFullSemver("1.0.3", new Config { NextVersion = "1.1.0" });
}

[Test]
Expand Down Expand Up @@ -148,7 +148,7 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigVersionShouldBeTagWith
fixture.Repository.MakeATaggedCommit(taggedVersion);
fixture.Repository.MakeCommits(5);

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

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

fixture.AssertFullSemver("1.1.0", new TestableConfig { NextVersion = "1.0.0" });
fixture.AssertFullSemver("1.1.0", new Config { NextVersion = "1.0.0" });
}

[Test]
Expand All @@ -169,13 +169,13 @@ public void CanSpecifyTagPrefixes()
fixture.Repository.MakeATaggedCommit(taggedVersion);
fixture.Repository.MakeCommits(5);

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

[Test]
public void CanSpecifyTagPrefixesAsRegex()
{
var config = new TestableConfig { TagPrefix = "version-|[vV]" };
var config = new Config { TagPrefix = "version-|[vV]" };
using var fixture = new EmptyRepositoryFixture();
var taggedVersion = "v1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
Expand All @@ -193,7 +193,7 @@ public void CanSpecifyTagPrefixesAsRegex()
[Test]
public void AreTagsNotAdheringToTagPrefixIgnored()
{
var config = new TestableConfig { TagPrefix = "" };
var config = new Config { TagPrefix = "" };
using var fixture = new EmptyRepositoryFixture();
var taggedVersion = "version-1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
Expand Down
Loading