Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
94 changes: 94 additions & 0 deletions src/GitVersionCore.Tests/Configuration/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,99 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
config.Branches["feature"].SourceBranches.ShouldBe(
new List<string> { "develop", "master", "release", "feature", "support", "hotfix" });
}

[Test]
public void ShouldNotOverrideAnythingWhenOverrideConfigIsEmpty()
{
const string text = @"
next-version: 1.2.3
tag-prefix: custom-tag-prefix-from-yml";
SetupConfigFileContent(text);

var expectedConfig = configProvider.Provide(repoPath, overrideConfig: null);
var overridenConfig = configProvider.Provide(repoPath, overrideConfig: new Config());

overridenConfig.AssemblyVersioningScheme.ShouldBe(expectedConfig.AssemblyVersioningScheme);
overridenConfig.AssemblyFileVersioningScheme.ShouldBe(expectedConfig.AssemblyFileVersioningScheme);
overridenConfig.AssemblyInformationalFormat.ShouldBe(expectedConfig.AssemblyInformationalFormat);
overridenConfig.AssemblyVersioningFormat.ShouldBe(expectedConfig.AssemblyVersioningFormat);
overridenConfig.AssemblyFileVersioningFormat.ShouldBe(expectedConfig.AssemblyFileVersioningFormat);
overridenConfig.VersioningMode.ShouldBe(expectedConfig.VersioningMode);
overridenConfig.TagPrefix.ShouldBe(expectedConfig.TagPrefix);
overridenConfig.ContinuousDeploymentFallbackTag.ShouldBe(expectedConfig.ContinuousDeploymentFallbackTag);
overridenConfig.NextVersion.ShouldBe(expectedConfig.NextVersion);
overridenConfig.MajorVersionBumpMessage.ShouldBe(expectedConfig.MajorVersionBumpMessage);
overridenConfig.MinorVersionBumpMessage.ShouldBe(expectedConfig.MinorVersionBumpMessage);
overridenConfig.PatchVersionBumpMessage.ShouldBe(expectedConfig.PatchVersionBumpMessage);
overridenConfig.NoBumpMessage.ShouldBe(expectedConfig.NoBumpMessage);
overridenConfig.LegacySemVerPadding.ShouldBe(expectedConfig.LegacySemVerPadding);
overridenConfig.BuildMetaDataPadding.ShouldBe(expectedConfig.BuildMetaDataPadding);
overridenConfig.CommitsSinceVersionSourcePadding.ShouldBe(expectedConfig.CommitsSinceVersionSourcePadding);
overridenConfig.TagPreReleaseWeight.ShouldBe(expectedConfig.TagPreReleaseWeight);
overridenConfig.CommitMessageIncrementing.ShouldBe(expectedConfig.CommitMessageIncrementing);
overridenConfig.Increment.ShouldBe(expectedConfig.Increment);
overridenConfig.CommitDateFormat.ShouldBe(expectedConfig.CommitDateFormat);
overridenConfig.MergeMessageFormats.ShouldBe(expectedConfig.MergeMessageFormats);
overridenConfig.UpdateBuildNumber.ShouldBe(expectedConfig.UpdateBuildNumber);

overridenConfig.Ignore.ShouldBeEquivalentTo(expectedConfig.Ignore);

overridenConfig.Branches.Keys.ShouldBe(expectedConfig.Branches.Keys);

foreach (var branch in overridenConfig.Branches.Keys)
{
overridenConfig.Branches[branch].ShouldBeEquivalentTo(expectedConfig.Branches[branch]);
}
}

[Test]
public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile()
{
const string text = "";
SetupConfigFileContent(text);
var config = configProvider.Provide(repoPath);

config.TagPrefix.ShouldBe("[vV]");
}

[Test]
public void ShouldUseTagPrefixFromConfigFileWhenProvided()
{
const string text = "tag-prefix: custom-tag-prefix-from-yml";
SetupConfigFileContent(text);
var config = configProvider.Provide(repoPath);

config.TagPrefix.ShouldBe("custom-tag-prefix-from-yml");
}

[Test]
public void ShouldOverrideTagPrefixWithOverrideConfigValue([Values] bool tagPrefixSetAtYmlFile)
{
var text = tagPrefixSetAtYmlFile ? "tag-prefix: custom-tag-prefix-from-yml" : "";
SetupConfigFileContent(text);
var config = configProvider.Provide(repoPath, overrideConfig: new Config { TagPrefix = "tag-prefix-from-override-config" });

config.TagPrefix.ShouldBe("tag-prefix-from-override-config");
}

[Test]
public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig()
{
const string text = "";
SetupConfigFileContent(text);
var config = configProvider.Provide(repoPath, overrideConfig: new Config { TagPrefix = null });

config.TagPrefix.ShouldBe("[vV]");
}

[Test]
public void ShouldNotOverrideTagPrefixFromConfigFileWhenNotSetInOverrideConfig()
{
const string text = "tag-prefix: custom-tag-prefix-from-yml";
SetupConfigFileContent(text);
var config = configProvider.Provide(repoPath, overrideConfig: new Config { TagPrefix = null });

config.TagPrefix.ShouldBe("custom-tag-prefix-from-yml");
}
}
}
3 changes: 1 addition & 2 deletions src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 @@ -225,7 +224,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn

var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);

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

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

Expand Down Expand Up @@ -67,7 +67,7 @@ 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 Config();
configuration ??= new TestableConfig();
configuration.Reset();
Console.WriteLine("---------");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private GitVersionContextBuilder AddBranch(string branchName)
public void Build()
{
var repo = repository ?? CreateRepository();
var config = configuration ?? new Config();
var config = configuration ?? new TestableConfig();

config.Reset();

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 Config().ApplyDefaults();
config ??= new TestableConfig().ApplyDefaults();
var options = Options.Create(new GitVersionOptions
{
WorkingDirectory = workingDirectory,
Expand Down
24 changes: 24 additions & 0 deletions src/GitVersionCore.Tests/Helpers/TestableConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using GitVersion.Model.Configuration;

namespace GitVersionCore.Tests.Helpers
{
[Obsolete("Do not use that config because it implicitly overwrites some settings (even default values). Use Config and override required settings explicitly instead.")]
public class TestableConfig : Config
{
public override void MergeTo(Config targetConfig)
{
targetConfig.Ignore = this.Ignore;

targetConfig.Branches.Clear();
targetConfig.Branches = this.Branches;

targetConfig.Increment = this.Increment;
targetConfig.NextVersion = this.NextVersion;
targetConfig.VersioningMode = this.VersioningMode;
targetConfig.AssemblyFileVersioningFormat = this.AssemblyFileVersioningFormat;
targetConfig.TagPrefix = this.TagPrefix;
targetConfig.TagPreReleaseWeight = this.TagPreReleaseWeight;
}
}
}
8 changes: 4 additions & 4 deletions src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
[Test]
public void CanChangeDevelopTagViaConfig()
{
var config = new Config
var config = new TestableConfig
{
Branches =
{
Expand Down Expand Up @@ -115,7 +115,7 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMasterDoesBumpDevelo
[Test]
public void CanHandleContinuousDelivery()
{
var config = new Config
var config = new TestableConfig
{
Branches =
{
Expand Down Expand Up @@ -205,7 +205,7 @@ public void TagOnHotfixShouldNotAffectDevelop()
[Test]
public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
{
var config = new Config
var config = new TestableConfig
{
VersioningMode = VersioningMode.ContinuousDeployment
};
Expand Down Expand Up @@ -246,7 +246,7 @@ public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish()
[Test]
public void CommitsSinceVersionSourceShouldNotGoDownUponMergingFeatureOnlyToDevelop()
{
var config = new Config
var config = new TestableConfig
{
VersioningMode = VersioningMode.ContinuousDeployment
};
Expand Down
20 changes: 10 additions & 10 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 Config
var config = new TestableConfig
{
Branches =
{
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 Config { VersioningMode = VersioningMode.ContinuousDeployment };
var configuration = new TestableConfig { VersioningMode = VersioningMode.ContinuousDeployment };
fixture.AssertFullSemver("1.2.0-longrunning.2", configuration);
}

[Test]
public void CanUseBranchNameOffAReleaseBranch()
{
var config = new Config
var config = new TestableConfig
{
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 Config
var config = new TestableConfig
{
Branches =
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public class WhenMasterMarkedAsIsDevelop
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new Config
var config = new TestableConfig
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -332,7 +332,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new Config
var config = new TestableConfig
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -411,7 +411,7 @@ public class WhenMasterMarkedAsIsDevelop
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new Config
var config = new TestableConfig
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -442,7 +442,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new Config
var config = new TestableConfig
{
Branches = new Dictionary<string, BranchConfig>
{
Expand Down Expand Up @@ -477,7 +477,7 @@ public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
[Test]
public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
{
var config = new Config
var config = new TestableConfig
{
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 Config
var config = new TestableConfig
{
VersioningMode = VersioningMode.ContinuousDeployment,
AssemblyVersioningScheme = AssemblyVersioningScheme.Major,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -128,7 +127,7 @@ public void PatchOlderReleaseExample()
[Test]
public void FeatureOnHotfixFeatureBranchDeleted()
{
var config = new Config
var config = new TestableConfig
{
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
VersioningMode = VersioningMode.ContinuousDeployment
Expand Down Expand Up @@ -181,7 +180,7 @@ public void FeatureOnHotfixFeatureBranchDeleted()
[Test]
public void FeatureOnHotfixFeatureBranchNotDeleted()
{
var config = new Config
var config = new TestableConfig
{
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 Config
private readonly Config config = new TestableConfig
{
VersioningMode = VersioningMode.Mainline
};
Expand Down Expand Up @@ -397,7 +397,7 @@ public void VerifyMergingMasterIntoAFeatureBranchWorksWithMultipleBranches()
[Test]
public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionOfMaster()
{
var currentConfig = new Config
var currentConfig = new TestableConfig
{
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 Config
var minorIncrementConfig = new TestableConfig
{
VersioningMode = VersioningMode.Mainline,
Increment = IncrementStrategy.Minor,
Expand Down
Loading