diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 938f6449f3..dd29e45ea8 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -27,6 +27,7 @@ * The process of increasing the version with bump message when `CommitMessageIncrementing` is enabled and increment strategy is `None` has been changed. * A new configuration property with name `version-in-branch-pattern` has been introduced. This setting only applies on branches where the option `is-release-branch` is set to `true`. Please notice that the branch name needs to be defined after the version number by default (instead of `support/lts-2.0.0` please name the branch like `support/2.0.0-lts`). * The `is-release-branch` property of the `hotfix` branch setting has been changed from `false` to `true`. If present the hotfix number will be considered now by default. +* In the GitHub and the Git Flow workflows the `label` property is by default set to an empty string on the `main` branch. This yields to a pre-release version on `main` with an empty tag. Instead of for instance `1.0.1+46` GitVersion generates the full semantic version `1.0.1-46` instead. This behavior can be changed to generate only stable versions (no pre-release version) with setting the label to `null` (Please keep in mind that the `label` property on root needs to be set to `null` as well, otherwise the fallback applies). This change is caused by issue #2347. ## v5.0.0 diff --git a/src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs b/src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs index 4328477bb8..ded2bb74fc 100644 --- a/src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs +++ b/src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs @@ -34,7 +34,7 @@ public void BeingOnBuildServerWithOutputJsonDoesNotFail() var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json /output buildserver", environments: env); result.ExitCode.ShouldBe(0); - const string expectedVersion = "0.0.1+5"; + const string expectedVersion = "0.0.1-5"; result.Output.ShouldContain($"##teamcity[buildNumber '{expectedVersion}']"); result.OutputVariables.ShouldNotBeNull(); result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion); @@ -53,7 +53,7 @@ public void BeingOnBuildServerWithOutputJsonAndOutputFileDoesNotFail(string outp var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: $" /output json /output buildserver /output file /outputfile {outputFile}", environments: env); result.ExitCode.ShouldBe(0); - const string expectedVersion = "0.0.1+5"; + const string expectedVersion = "0.0.1-5"; result.Output.ShouldContain($"##teamcity[buildNumber '{expectedVersion}']"); result.OutputVariables.ShouldNotBeNull(); result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion); diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index a04994326f..4b4fe87762 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -13,7 +13,6 @@ update-build-number: true semantic-version-format: Strict branches: develop: - mode: ContinuousDeployment label: alpha increment: Minor prevent-increment-of-merged-branch-version: false @@ -40,6 +39,7 @@ branches: is-mainline: true pre-release-weight: 55000 release: + mode: ContinuousDelivery label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -70,7 +70,7 @@ branches: is-source-branch-for: [] pre-release-weight: 30000 pull-request: - mode: ContinuousDelivery + mode: ContinuousDeployment label: PullRequest increment: Inherit label-number-pattern: '[/-](?\d+)' @@ -126,7 +126,7 @@ branches: is-source-branch-for: [] ignore: sha: [] -mode: ContinuousDelivery +mode: ContinuousDeployment label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs index 1fe0cfc46c..cdd25cd6af 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs @@ -4,6 +4,7 @@ using GitVersion.Extensions; using GitVersion.Helpers; using GitVersion.Logging; +using GitVersion.VersionCalculation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -33,21 +34,26 @@ public void Setup() [Test] public void OverwritesDefaultsWithProvidedConfig() { - var defaultConfig = this.configurationProvider.ProvideForDirectory(this.repoPath); + var defaultConfiguration = this.configurationProvider.ProvideForDirectory(this.repoPath); const string text = @" next-version: 2.0.0 branches: develop: - mode: ContinuousDeployment + increment: Major + mode: ContinuousDelivery label: dev"; SetupConfigFileContent(text); var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.0.0"); configuration.Branches.ShouldNotBeNull(); - configuration.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment); - configuration.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode); - configuration.Branches["develop"].Label.ShouldBe("dev"); + + var developConfiguration = configuration.Branches["develop"]; + developConfiguration.Increment.ShouldBe(IncrementStrategy.Major); + developConfiguration.Increment.ShouldNotBe(defaultConfiguration.Branches["develop"].Increment); + developConfiguration.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery); + developConfiguration.VersioningMode.ShouldNotBe(defaultConfiguration.Branches["develop"].VersioningMode); + developConfiguration.Label.ShouldBe("dev"); } [Test] diff --git a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs index 10b9c026b8..1b33127e2d 100644 --- a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs +++ b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs @@ -48,8 +48,8 @@ public void Cleanup() // Note: use same name twice to see if changing commits works on same (cached) repository [NonParallelizable] - [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2+56")] - [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "2dc142a4a4df77db61a00d9fb7510b18b3c2c85a", "5.8.2+47")] + [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2-56")] + [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "2dc142a4a4df77db61a00d9fb7510b18b3c2c85a", "5.8.2-47")] public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer) { var root = PathHelper.Combine(this.workDirectory, name); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs b/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs new file mode 100644 index 0000000000..833c10e5ce --- /dev/null +++ b/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs @@ -0,0 +1,445 @@ +using GitVersion.Configuration; +using GitVersion.VersionCalculation; + +namespace GitVersion.Core.Tests.IntegrationTests; + +/// +/// - For mode 1 the main-releases are especially not marked with dedicated tags. +/// - For mode 2, 3 and 4 the pre-releases and the main-releases are always marked with dedicated tags. +/// - Continuous deployment with is mainline false requires always a pre-release tag unless the commit is tagged +/// +[TestFixture] +internal class ComparingTheBehaviorOfDifferentVersioningModes +{ + private static readonly GitHubFlowConfigurationBuilder configurationBuilder = GitHubFlowConfigurationBuilder.New + .WithLabel(null).WithIsMainline(null) + .WithBranch("main", _ => _ + .WithIncrement(IncrementStrategy.Patch).WithVersioningMode(null).WithLabel(null) + ).WithBranch("feature", _ => _ + .WithIncrement(IncrementStrategy.Inherit).WithVersioningMode(null).WithLabel("{BranchName}") + ); + + private static readonly IGitVersionConfiguration trunkBased = configurationBuilder + .WithVersioningMode(VersioningMode.Mainline).WithIsMainline(true) + .WithBranch("main", _ => _.WithIsMainline(true)) + .WithBranch("feature", _ => _.WithIsMainline(true)) + .Build(); + + private static readonly IGitVersionConfiguration continuousDeployment = configurationBuilder + .WithVersioningMode(VersioningMode.ContinuousDeployment).WithIsMainline(true) + .WithBranch("main", _ => _.WithIsMainline(true)) + .WithBranch("feature", _ => _.WithIsMainline(true)) + .Build(); + + private static readonly IGitVersionConfiguration continuousDelivery = configurationBuilder + .WithVersioningMode(VersioningMode.ContinuousDeployment).WithIsMainline(false) + .WithBranch("main", _ => _.WithIsMainline(false)) + .WithBranch("feature", _ => _.WithIsMainline(false)) + .Build(); + + private static readonly IGitVersionConfiguration manualDeployment = configurationBuilder + .WithVersioningMode(VersioningMode.ContinuousDelivery).WithIsMainline(false) + .WithBranch("main", _ => _.WithIsMainline(false)) + .WithBranch("feature", _ => _.WithIsMainline(false)) + .Build(); + + [Test] + public void ExpectedBehavior() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("1.0.0"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0", trunkBased); + fixture.AssertFullSemver("1.0.0", continuousDeployment); + fixture.AssertFullSemver("1.0.0", continuousDelivery); + fixture.AssertFullSemver("1.0.0", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.1", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-1", continuousDelivery); + fixture.AssertFullSemver("1.0.1-1+1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.2", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-2", continuousDelivery); + fixture.AssertFullSemver("1.0.1-1+2", manualDeployment); + + fixture.ApplyTag("1.0.1-alpha.1"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-alpha.1", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-alpha.1", continuousDelivery); + fixture.AssertFullSemver("1.0.1-alpha.1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-alpha.2", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-alpha.2", continuousDelivery); + fixture.AssertFullSemver("1.0.1-alpha.2+1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-alpha.3", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-alpha.3", continuousDelivery); + fixture.AssertFullSemver("1.0.1-alpha.2+2", manualDeployment); + + fixture.MakeATaggedCommit("1.0.1-beta.1"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-beta.1", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-beta.1", continuousDelivery); + fixture.AssertFullSemver("1.0.1-beta.1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-beta.2", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-beta.2", continuousDelivery); + fixture.AssertFullSemver("1.0.1-beta.2+1", manualDeployment); + + fixture.MakeATaggedCommit("1.0.1-beta.2"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-beta.2", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-beta.2", continuousDelivery); + fixture.AssertFullSemver("1.0.1-beta.2", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1-beta.3", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1-beta.3", continuousDelivery); + fixture.AssertFullSemver("1.0.1-beta.3+1", manualDeployment); + + fixture.ApplyTag("1.0.1"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.1", trunkBased); + fixture.AssertFullSemver("1.0.1", continuousDeployment); + fixture.AssertFullSemver("1.0.1", continuousDelivery); + fixture.AssertFullSemver("1.0.1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.2", trunkBased); + fixture.AssertFullSemver("1.0.2", continuousDeployment); + fixture.AssertFullSemver("1.0.2-1", continuousDelivery); + fixture.AssertFullSemver("1.0.2-1+1", manualDeployment); + + fixture.ApplyTag("1.0.2-1"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.2-1", trunkBased); + fixture.AssertFullSemver("1.0.2", continuousDeployment); + fixture.AssertFullSemver("1.0.2-1", continuousDelivery); + fixture.AssertFullSemver("1.0.2-1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.2-2", trunkBased); + fixture.AssertFullSemver("1.0.2", continuousDeployment); + fixture.AssertFullSemver("1.0.2-2", continuousDelivery); + fixture.AssertFullSemver("1.0.2-2+1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.0.2-3", trunkBased); + fixture.AssertFullSemver("1.0.2", continuousDeployment); + fixture.AssertFullSemver("1.0.2-3", continuousDelivery); + fixture.AssertFullSemver("1.0.2-2+2", manualDeployment); + } + + [Test] + public void MainRelease() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.2", trunkBased); + fixture.AssertFullSemver("0.0.2", continuousDeployment); + fixture.AssertFullSemver("0.0.2", continuousDelivery); + fixture.AssertFullSemver("0.0.2", manualDeployment); + } + + [Test] + public void MergeFeatureToMain() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.BranchTo("feature/test"); + fixture.MakeACommit(); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.3-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.0.3-test.1", continuousDelivery); + fixture.AssertFullSemver("0.0.3-test.1+1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.0.3-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.0.3-test.2", continuousDelivery); + fixture.AssertFullSemver("0.0.3-test.1+2", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.3", trunkBased); + fixture.AssertFullSemver("0.0.3", continuousDeployment); + fixture.AssertFullSemver("0.0.3-3", continuousDelivery); + fixture.AssertFullSemver("0.0.3-1+3", manualDeployment); + } + + [Test] + public void MergeFeatureToMainWithPreviousCommits() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.MakeACommit(); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.3", trunkBased); + fixture.AssertFullSemver("0.0.3", continuousDeployment); + fixture.AssertFullSemver("0.0.3-1", continuousDelivery); + fixture.AssertFullSemver("0.0.3-1+1", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.4", trunkBased); + fixture.AssertFullSemver("0.0.3", continuousDeployment); + fixture.AssertFullSemver("0.0.3-2", continuousDelivery); + fixture.AssertFullSemver("0.0.3-1+2", manualDeployment); + + fixture.BranchTo("feature/test"); + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.0.5-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.0.3-test.3", continuousDelivery); + fixture.AssertFullSemver("0.0.3-test.1+3", manualDeployment); + + fixture.MakeACommit(); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.0.5-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.0.3-test.4", continuousDelivery); + fixture.AssertFullSemver("0.0.3-test.1+4", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.0.5", trunkBased); + fixture.AssertFullSemver("0.0.3", continuousDeployment); + fixture.AssertFullSemver("0.0.3-5", continuousDelivery); + fixture.AssertFullSemver("0.0.3-1+5", manualDeployment); + } + + [Test] + public void MergeFeatureToMainWithMinorMinorSemversionIncrement() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.BranchTo("feature/test"); + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.1.0-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.1.0-test.1", continuousDelivery); + fixture.AssertFullSemver("0.1.0-test.1+1", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.2.0-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.1.0-test.2", continuousDelivery); + fixture.AssertFullSemver("0.1.0-test.1+2", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.2.0", trunkBased); + fixture.AssertFullSemver("0.1.0", continuousDeployment); + fixture.AssertFullSemver("0.1.0-3", continuousDelivery); + fixture.AssertFullSemver("0.1.0-1+3", manualDeployment); + } + + [Test] + public void MergeFeatureToMainWithMajorMinorSemversionIncrement() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.BranchTo("feature/test"); + fixture.MakeACommit("+semver: major"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("1.0.0-test.1", continuousDelivery); + fixture.AssertFullSemver("1.0.0-test.1+1", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("1.1.0-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("1.0.0-test.2", continuousDelivery); + fixture.AssertFullSemver("1.0.0-test.1+2", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.1.0", trunkBased); + fixture.AssertFullSemver("1.0.0", continuousDeployment); + fixture.AssertFullSemver("1.0.0-3", continuousDelivery); + fixture.AssertFullSemver("1.0.0-1+3", manualDeployment); + } + + [Test] + public void MergeFeatureToMainWithPreviousCommitsAndMinorMinorSemversionIncrement() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.1.0", trunkBased); + fixture.AssertFullSemver("0.1.0", continuousDeployment); + fixture.AssertFullSemver("0.1.0-1", continuousDelivery); + fixture.AssertFullSemver("0.1.0-1+1", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.2.0", trunkBased); + fixture.AssertFullSemver("0.1.0", continuousDeployment); + fixture.AssertFullSemver("0.1.0-2", continuousDelivery); + fixture.AssertFullSemver("0.1.0-1+2", manualDeployment); + + fixture.BranchTo("feature/test"); + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.3.0-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.1.0-test.3", continuousDelivery); + fixture.AssertFullSemver("0.1.0-test.1+3", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.4.0-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("0.1.0-test.4", continuousDelivery); + fixture.AssertFullSemver("0.1.0-test.1+4", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("0.4.0", trunkBased); + fixture.AssertFullSemver("0.1.0", continuousDeployment); + fixture.AssertFullSemver("0.1.0-5", continuousDelivery); + fixture.AssertFullSemver("0.1.0-1+5", manualDeployment); + } + + [Test] + public void MergeFeatureToMainWithPreviousCommitsAndMinorMajorSemversionIncrement() + { + using var fixture = new EmptyRepositoryFixture("main"); + + fixture.MakeATaggedCommit("0.0.2"); + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + fixture.AssertFullSemver("0.1.0", trunkBased); + fixture.AssertFullSemver("0.1.0", continuousDeployment); + fixture.AssertFullSemver("0.1.0-1", continuousDelivery); + fixture.AssertFullSemver("0.1.0-1+1", manualDeployment); + + fixture.MakeACommit("+semver: major"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.1.0", trunkBased); + fixture.AssertFullSemver("1.0.0", continuousDeployment); + fixture.AssertFullSemver("1.0.0-2", continuousDelivery); + fixture.AssertFullSemver("1.0.0-1+2", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("1.1.0", trunkBased); + fixture.AssertFullSemver("1.0.0", continuousDeployment); + fixture.AssertFullSemver("1.0.0-3", continuousDelivery); + fixture.AssertFullSemver("1.0.0-1+3", manualDeployment); + + fixture.BranchTo("feature/test"); + fixture.MakeACommit("+semver: major"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("2.1.0-test.1", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("1.0.0-test.4", continuousDelivery); + fixture.AssertFullSemver("1.0.0-test.1+4", manualDeployment); + + fixture.MakeACommit("+semver: minor"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("2.2.0-test.2", trunkBased); + //fixture.AssertFullSemver("?", continuousDeployment); + fixture.AssertFullSemver("1.0.0-test.5", continuousDelivery); + fixture.AssertFullSemver("1.0.0-test.1+5", manualDeployment); + + fixture.Checkout("main"); + fixture.MergeNoFF("feature/test"); + fixture.Repository.Branches.Remove("feature/test"); + + // ✅ succeeds as expected + //fixture.AssertFullSemver("2.2.0", trunkBased); + fixture.AssertFullSemver("1.0.0", continuousDeployment); + fixture.AssertFullSemver("1.0.0-6", continuousDelivery); + fixture.AssertFullSemver("1.0.0-1+6", manualDeployment); + } +} diff --git a/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs b/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs index fedeb94a0b..8f30cec592 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs @@ -27,7 +27,7 @@ public void ShouldTreatTheFeatureBranchLikeTheFirstReleaseBranchWhenItHasBeenBra fixture.Repository.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.BranchTo("release/1.0.0"); @@ -43,7 +43,7 @@ public void ShouldTreatTheFeatureBranchLikeTheFirstReleaseBranchWhenItHasBeenBra fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+2", configuration); + fixture.AssertFullSemver("0.0.1-2", configuration); fixture.BranchTo("release/1.1.0"); fixture.Checkout("release/1.0.0"); @@ -398,7 +398,7 @@ public void ShouldTreatTheFeatureBranchLikeTheReleaseBranchWhenItHasBeenBranched fixture.Repository.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.BranchTo("release/1.0.0"); @@ -463,7 +463,7 @@ public void ShouldTreatTheMergeFromReleaseToDevelopLikeTheReleaseBranchHasNeverB fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.BranchTo("develop"); @@ -507,12 +507,12 @@ public void ShouldTreatTheMergeFromReleaseToDevelopLikeTheReleaseBranchHasNeverB fixture.Repository.Branches.Remove("release/1.0.0"); - // ❔ expected: "0.1.0+6" because the release has been canceled and should be treated like it was never existing + // ✅ succeeds as expected fixture.AssertFullSemver("1.1.0-alpha.4", configuration); fixture.MakeACommit(); - // ❔ expected: "0.1.0+7" because the release has been canceled and should be treated like it was never existing + // ✅ succeeds as expected fixture.AssertFullSemver("1.1.0-alpha.5", configuration); fixture.Repository.DumpGraph(); @@ -541,7 +541,7 @@ public void ShouldOnlyTrackTheCommitsOnDevelopBranchForNextReleaseWhenReleaseHas fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.BranchTo("develop"); @@ -581,8 +581,8 @@ public void ShouldOnlyTrackTheCommitsOnDevelopBranchForNextReleaseWhenReleaseHas fixture.Checkout("main"); fixture.MergeNoFF("release/1.0.0"); - // ❔ expected: "0.0.1+4" because until the commit is not tagged it's a hotfix - fixture.AssertFullSemver("1.0.0+0", configuration); + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0-0", configuration); fixture.ApplyTag("1.0.0"); @@ -601,7 +601,7 @@ public void ShouldOnlyTrackTheCommitsOnDevelopBranchForNextReleaseWhenReleaseHas fixture.Repository.Branches.Remove("release/1.0.0"); - // ❔ expected: "1.1.0-alpha.2" because only one commit and one merge has been pushed + // ✅ succeeds as expected fixture.AssertFullSemver("1.1.0-alpha.6", configuration); fixture.Repository.DumpGraph(); @@ -630,7 +630,7 @@ public void ShouldNotConsiderTheMergeCommitFromReleaseToMainWhenCommitHasNotBeen fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.BranchTo("develop"); @@ -670,13 +670,13 @@ public void ShouldNotConsiderTheMergeCommitFromReleaseToMainWhenCommitHasNotBeen fixture.Checkout("main"); fixture.MergeNoFF("release/1.0.0"); - // ❔ expected: "0.0.1+4" because until the commit is not tagged it's a hotfix - fixture.AssertFullSemver("1.0.0+0", configuration); + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0-0", configuration); fixture.Repository.Branches.Remove("release/1.0.0"); - // ❔ expected: "0.0.1+4" because until the commit is not tagged it's a hotfix - fixture.AssertFullSemver("1.0.0+0", configuration); + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0-0", configuration); fixture.ApplyTag("1.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs index da95be489c..d24d6de5d0 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs @@ -390,7 +390,6 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToTrueForDevelopCommit public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommitsSinceVersionSourceShouldNotGoDownWhenMergingHotfixToDevelop() { var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.ContinuousDeployment) .WithBranch("develop", builder => builder .WithPreventIncrementOfMergedBranchVersion(false) ) @@ -413,7 +412,7 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommi const string ReleaseBranch = "release/1.1.0"; Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch(ReleaseBranch)); fixture.Repository.MakeCommits(3); - fixture.AssertFullSemver("1.1.0-beta.3", configuration); + fixture.AssertFullSemver("1.1.0-beta.1+3", configuration); // Simulate a GitFlow release finish. fixture.Checkout(MainBranch); @@ -460,23 +459,23 @@ public void NextVersionShouldBeConsideredOnTheMainBranch() fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configurationBuilder.Build()); + fixture.AssertFullSemver("0.0.1-1", configurationBuilder.Build()); configurationBuilder.WithNextVersion("1.0.0"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0+1", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-1", configurationBuilder.Build()); fixture.MakeACommit(); configurationBuilder.WithNextVersion(null); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+2", configurationBuilder.Build()); + fixture.AssertFullSemver("0.0.1-2", configurationBuilder.Build()); configurationBuilder.WithNextVersion("1.0.0"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0+2", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-2", configurationBuilder.Build()); } /// @@ -540,15 +539,13 @@ public void PreventDecrementationOfVersionsOnTheMainBranch() // Merge from develop to main fixture.BranchTo("main"); - // ❔ expected: "0.0.1+4" - // This behavior needs to be changed for the git flow workflow using the track-merge-message or track-merge-target options. - // [Bug] track-merge-changes produces unexpected result when combining hotfix and support branches #3052 - fixture.AssertFullSemver("1.0.0+0", configurationBuilder.Build()); + // ✅ succeeds as expected + fixture.AssertFullSemver("1.0.0-0", configurationBuilder.Build()); configurationBuilder.WithNextVersion("1.0.0"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0+0", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-0", configurationBuilder.Build()); // Mark this version as RTM fixture.ApplyTag("1.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs b/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs index 1def653a52..df3ab8e848 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs @@ -202,7 +202,7 @@ public void GitFlowMajorRelease() fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/2.0.0"); fixture.Checkout(MainBranch); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); fixture.ApplyTag("2.0.0"); fixture.AssertFullSemver("2.0.0"); @@ -233,7 +233,7 @@ public void GitFlowSupportHotfixRelease() fixture.Checkout("1.3.0"); fixture.BranchToFromTag("support/1.x", "1.3.0", MainBranch, "support"); fixture.MakeACommit(); - fixture.AssertFullSemver("1.3.1+1"); + fixture.AssertFullSemver("1.3.1-1"); fixture.BranchTo("hotfix/1.3.1", "hotfix2"); fixture.SequenceDiagram.Activate("hotfix/1.3.1"); @@ -248,7 +248,7 @@ public void GitFlowSupportHotfixRelease() fixture.MergeNoFF("hotfix/1.3.1"); fixture.SequenceDiagram.Destroy("hotfix/1.3.1"); fixture.SequenceDiagram.NoteOver("Hotfix branches are deleted once merged", "hotfix/1.3.1"); - fixture.AssertFullSemver("1.3.1+4"); + fixture.AssertFullSemver("1.3.1-4"); fixture.ApplyTag("1.3.1"); fixture.AssertFullSemver("1.3.1"); Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); @@ -291,7 +291,7 @@ public void GitFlowSupportMinorRelease() fixture.MergeNoFF("release/1.4.0"); fixture.SequenceDiagram.Destroy("release/1.4.0"); fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/1.4.0"); - fixture.AssertFullSemver("1.4.0+0"); + fixture.AssertFullSemver("1.4.0-0"); fixture.ApplyTag("1.4.0"); fixture.AssertFullSemver("1.4.0"); Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); @@ -309,7 +309,7 @@ public void GitHubFlowFeatureBranch() // Branch to develop fixture.MakeACommit(); - fixture.AssertFullSemver("1.2.1+1"); + fixture.AssertFullSemver("1.2.1-1"); // Open Pull Request const string branchName = "feature/myFeature"; @@ -324,7 +324,7 @@ public void GitHubFlowFeatureBranch() fixture.MergeNoFF(branchName); fixture.SequenceDiagram.Destroy(branchName); fixture.SequenceDiagram.NoteOver("Feature branches should\r\nbe deleted once merged", branchName); - fixture.AssertFullSemver("1.2.1+3"); + fixture.AssertFullSemver("1.2.1-3"); } [Test] @@ -339,7 +339,7 @@ public void GitHubFlowPullRequestBranch() // Branch to develop fixture.MakeACommit(); - fixture.AssertFullSemver("1.2.1+1"); + fixture.AssertFullSemver("1.2.1-1"); // Open Pull Request fixture.BranchTo("pull/2/merge", "pr"); @@ -354,7 +354,7 @@ public void GitHubFlowPullRequestBranch() fixture.SequenceDiagram.Destroy("pull/2/merge"); fixture.SequenceDiagram.NoteOver("Feature branches/pr's should\r\n" + "be deleted once merged", "pull/2/merge"); - fixture.AssertFullSemver("1.2.1+3"); + fixture.AssertFullSemver("1.2.1-3"); } [Test] @@ -392,11 +392,11 @@ public void GitHubFlowMajorRelease() fixture.SequenceDiagram.Destroy("release/2.0.0"); fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/2.0.0"); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); fixture.ApplyTag("2.0.0"); fixture.AssertFullSemver("2.0.0"); fixture.MakeACommit(); fixture.Repository.DumpGraph(); - fixture.AssertFullSemver("2.0.1+1"); + fixture.AssertFullSemver("2.0.1-1"); } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs index b98bc6eec2..59ca1126d6 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -294,7 +294,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() fixture.MakeACommit(); fixture.Checkout(MainBranch); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1", configuration); // create a feature branch from main and verify the version fixture.BranchTo("feature/test"); @@ -317,7 +317,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() // merge release into main fixture.Checkout(MainBranch); fixture.MergeNoFF("release/1.0.0"); - fixture.AssertFullSemver("1.0.1+2", configuration); + fixture.AssertFullSemver("1.0.1-2", configuration); // create a feature branch from main and verify the version fixture.BranchTo("feature/test"); @@ -384,7 +384,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() fixture.MakeACommit(); fixture.Checkout(MainBranch); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1", configuration); // create a misnamed feature branch (i.e. it uses the default configuration) from main and verify the version fixture.BranchTo("misnamed"); @@ -407,7 +407,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() // merge release into main fixture.Checkout(MainBranch); fixture.MergeNoFF("release/1.0.0"); - fixture.AssertFullSemver("1.0.1+2", configuration); + fixture.AssertFullSemver("1.0.1-2", configuration); // create a misnamed feature branch (i.e. it uses the default configuration) from main and verify the version fixture.BranchTo("misnamed"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/GitflowScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/GitflowScenarios.cs index 681d42759f..9b7fc6ce56 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/GitflowScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/GitflowScenarios.cs @@ -33,7 +33,7 @@ public void GitflowComplexExample() fixture.AssertFullSemver("1.1.0-beta.1+1"); fixture.Checkout(MainBranch); fixture.MergeNoFF(release1Branch); - fixture.AssertFullSemver("1.1.0+0"); + fixture.AssertFullSemver("1.1.0-0"); fixture.ApplyTag("1.1.0"); fixture.AssertFullSemver("1.1.0"); fixture.Checkout(developBranch); @@ -56,7 +56,7 @@ public void GitflowComplexExample() fixture.AssertFullSemver("1.2.0-beta.1+1"); fixture.Checkout(MainBranch); fixture.MergeNoFF(release2Branch); - fixture.AssertFullSemver("1.2.0+0"); + fixture.AssertFullSemver("1.2.0-0"); fixture.ApplyTag("1.2.0"); fixture.AssertFullSemver("1.2.0"); fixture.Checkout(developBranch); @@ -71,7 +71,7 @@ public void GitflowComplexExample() fixture.AssertFullSemver("1.2.1-beta.1+1"); fixture.Checkout(MainBranch); fixture.MergeNoFF(hotfixBranch); - fixture.AssertFullSemver("1.2.1+2"); + fixture.AssertFullSemver("1.2.1-2"); fixture.ApplyTag("1.2.1"); fixture.AssertFullSemver("1.2.1"); fixture.Checkout(developBranch); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index d8ce805c34..9679271260 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -1,7 +1,6 @@ using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Extensions; -using GitVersion.VersionCalculation; using LibGit2Sharp; namespace GitVersion.Core.Tests.IntegrationTests; @@ -31,7 +30,7 @@ public void PatchLatestReleaseExample() Commands.Checkout(fixture.Repository, MainBranch); fixture.Repository.MergeNoFF("hotfix-1.2.1", Generate.SignatureNow()); - fixture.AssertFullSemver("1.2.1+4"); + fixture.AssertFullSemver("1.2.1-4"); fixture.Repository.ApplyTag("1.2.1"); fixture.AssertFullSemver("1.2.1"); @@ -108,7 +107,7 @@ public void PatchOlderReleaseExample() // Merge hotfix into support branch to complete hotfix fixture.Checkout("support-1.1"); fixture.MergeNoFF("hotfix-1.1.1"); - fixture.AssertFullSemver("1.1.1+5"); + fixture.AssertFullSemver("1.1.1-5"); fixture.ApplyTag("1.1.1"); fixture.AssertFullSemver("1.1.1"); @@ -127,11 +126,6 @@ public void FeatureOnHotfixFeatureBranchDeleted() { var configuration = GitFlowConfigurationBuilder.New .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("feature", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment)) - .WithBranch("hotfix", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment)) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -146,7 +140,7 @@ public void FeatureOnHotfixFeatureBranchDeleted() // create release branch fixture.BranchTo(release450); - fixture.AssertFullSemver("4.5.0-beta.0", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+0", configuration); fixture.MakeACommit("blabla"); fixture.Checkout("develop"); fixture.MergeNoFF(release450); @@ -167,7 +161,7 @@ public void FeatureOnHotfixFeatureBranchDeleted() fixture.Checkout(hotfix451); fixture.MergeNoFF(featureBranch); // commit 2 fixture.Repository.Branches.Remove(featureBranch); - fixture.AssertFullSemver("4.5.1-beta.3", configuration); + fixture.AssertFullSemver("4.5.1-beta.1+3", configuration); } /// @@ -178,11 +172,6 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() { var configuration = GitFlowConfigurationBuilder.New .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("feature", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment)) - .WithBranch("hotfix", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment)) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -197,7 +186,7 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() // create release branch fixture.BranchTo(release450); - fixture.AssertFullSemver("4.5.0-beta.0", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+0", configuration); fixture.MakeACommit("blabla"); fixture.Checkout("develop"); fixture.MergeNoFF(release450); @@ -218,7 +207,7 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() fixture.Checkout(hotfix451); fixture.MergeNoFF(featureBranch); // commit 2 - fixture.AssertFullSemver("4.5.1-beta.3", configuration); + fixture.AssertFullSemver("4.5.1-beta.1+3", configuration); } [Test] diff --git a/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs index e83637a5db..5d08ffac15 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs @@ -6,10 +6,10 @@ namespace GitVersion.Core.Tests.IntegrationTests; [TestFixture] public class IgnoreBeforeScenarios : TestBase { - [TestCase(null, "0.0.1+0")] - [TestCase("0.0.1", "0.0.1+0")] - [TestCase("0.1.0", "0.1.0+0")] - [TestCase("1.0.0", "1.0.0+0")] + [TestCase(null, "0.0.1-0")] + [TestCase("0.0.1", "0.0.1-0")] + [TestCase("0.1.0", "0.1.0-0")] + [TestCase("1.0.0", "1.0.0-0")] public void ShouldFallbackToBaseVersionWhenAllCommitsAreIgnored(string? nextVersion, string expectedFullSemVer) { using var fixture = new EmptyRepositoryFixture(); @@ -22,10 +22,10 @@ public void ShouldFallbackToBaseVersionWhenAllCommitsAreIgnored(string? nextVers fixture.AssertFullSemver(expectedFullSemVer, configuration); } - [TestCase(null, "0.0.1+1")] - [TestCase("0.0.1", "0.0.1+1")] - [TestCase("0.1.0", "0.1.0+1")] - [TestCase("1.0.0", "1.0.0+1")] + [TestCase(null, "0.0.1-1")] + [TestCase("0.0.1", "0.0.1-1")] + [TestCase("0.1.0", "0.1.0-1")] + [TestCase("1.0.0", "1.0.0-1")] public void ShouldNotFallbackToBaseVersionWhenAllCommitsAreNotIgnored(string? nextVersion, string expectedFullSemVer) { using var fixture = new EmptyRepositoryFixture(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs index 81f5f6b038..38d3ebe169 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs @@ -18,7 +18,7 @@ public void CanHandleContinuousDelivery() using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeCommits(2); - fixture.AssertFullSemver("1.0.1+2", configuaration); + fixture.AssertFullSemver("1.0.1-1+2", configuaration); } [Test] @@ -45,7 +45,7 @@ public void GivenARepositoryWithCommitsButNoTagsVersionShouldBe01() fixture.Repository.MakeACommit(); // When - fixture.AssertFullSemver("0.0.1+3"); + fixture.AssertFullSemver("0.0.1-3"); } [Test] @@ -59,7 +59,7 @@ public void GivenARepositoryWithCommitsButBadTagsVersionShouldBe01() fixture.Repository.MakeACommit(); // When - fixture.AssertFullSemver("0.0.1+3"); + fixture.AssertFullSemver("0.0.1-3"); } [Test] @@ -76,7 +76,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0 Commands.Checkout(fixture.Repository, commit); // When - fixture.AssertFullSemver("0.0.1+3", onlyTrackedBranches: false); + fixture.AssertFullSemver("0.0.1-3", onlyTrackedBranches: false); } [Test] @@ -89,7 +89,7 @@ public void GivenARepositoryWithTagAndNextVersionInConfigVersionShouldMatchVersi fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.1.0+5", configuration); + fixture.AssertFullSemver("1.1.0-5", configuration); } [Test] @@ -111,12 +111,12 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.0.4+1"); + fixture.AssertFullSemver("1.0.4-1"); // I'm not sure if the postfix +1 is correct here... // but the next version configuration property is something for the user to manipulate the resulting version. var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.1.0").Build(); - fixture.AssertFullSemver("1.1.0+1", configuration); + fixture.AssertFullSemver("1.1.0-1", configuration); } [Test] @@ -137,9 +137,9 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.0.4+1"); + fixture.AssertFullSemver("1.0.4-1"); var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.4").Build(); - fixture.AssertFullSemver("1.0.4+1", configuration); + fixture.AssertFullSemver("1.0.4-1", configuration); } [Test] @@ -150,7 +150,7 @@ public void GivenARepositoryWithTagAndNoNextVersionTxtFileVersionShouldBeTagWith fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.0.4+5"); + fixture.AssertFullSemver("1.0.4-5"); } [Test] @@ -172,7 +172,7 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigVersionShouldBeTagWith fixture.Repository.MakeCommits(5); var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.0").Build(); - fixture.AssertFullSemver("1.1.1+5", configuration); + fixture.AssertFullSemver("1.1.1-5", configuration); } [Test] @@ -195,7 +195,7 @@ public void CanSpecifyTagPrefixes() fixture.Repository.MakeCommits(5); var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix("version-").Build(); - fixture.AssertFullSemver("1.0.4+5", configuration); + fixture.AssertFullSemver("1.0.4-5", configuration); } [Test] @@ -207,13 +207,13 @@ public void CanSpecifyTagPrefixesAsRegex() fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.0.4+5", configuration); + fixture.AssertFullSemver("1.0.4-5", configuration); taggedVersion = "version-1.0.5"; fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.0.6+5", configuration); + fixture.AssertFullSemver("1.0.6-5", configuration); } [Test] @@ -225,12 +225,12 @@ public void AreTagsNotAdheringToTagPrefixIgnored() fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("0.0.1+6", configuration); + fixture.AssertFullSemver("0.0.1-6", configuration); taggedVersion = "bad/1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); - fixture.AssertFullSemver("0.0.1+7", configuration); + fixture.AssertFullSemver("0.0.1-7", configuration); } [Test] @@ -372,8 +372,8 @@ public void PreventDecrementationOfVersionsOnTheDevelopmentBranch() fixture.AssertFullSemver("1.1.0-alpha.3", configurationBuilder.Build()); } - [TestCase(true, "1.1.0+0")] - [TestCase(false, "1.0.1+4")] + [TestCase(true, "1.1.0-0")] + [TestCase(false, "1.0.1-4")] public void TrackMergeMessageShouldBeConsideredOnTheMainBranch(bool trackMergeMessage, string expectedSemanticVersion) { using EmptyRepositoryFixture fixture = new("main"); @@ -394,7 +394,7 @@ public void TrackMergeMessageShouldBeConsideredOnTheMainBranch(bool trackMergeMe fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1", configuration); fixture.MergeNoFF("release/1.1.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs index a946f5cf3a..7910912faf 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs @@ -13,7 +13,7 @@ private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowC .WithBranch("develop", builder => builder.WithVersioningMode(VersioningMode.Mainline)) .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) .WithBranch("support", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .WithBranch("pull-request", builder => builder.WithVersioningMode(VersioningMode.Mainline)); + .WithBranch("pull-request", builder => builder.WithVersioningMode(null)); [Test] public void VerifyNonMainMainlineVersionIdenticalAsMain() diff --git a/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs index 7580804108..d6a6943d40 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs @@ -124,7 +124,7 @@ public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label, Commands.Checkout(fixture.Repository, branchName); fixture.Repository.MakeCommits(5); - var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5"; + var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.5"; fixture.AssertFullSemver(expectedFullSemVer, configuration); } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs index 62d7d7e8bd..ee208dd8ca 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs @@ -26,7 +26,7 @@ public void DoNotBlowUpWhenMainAndDevelopPointAtSameCommit() Commands.Checkout(fixture.LocalRepositoryFixture.Repository, fixture.Repository.Head.Tip); fixture.LocalRepositoryFixture.Repository.Branches.Remove(MainBranch); fixture.InitializeRepo(); - fixture.AssertFullSemver("1.0.1+1"); + fixture.AssertFullSemver("1.0.1-1"); } [Test] @@ -63,7 +63,7 @@ public void AllowHavingMasterInsteadOfMain() fixture.BranchTo("master"); fixture.Repository.Branches.Remove("main"); - fixture.AssertFullSemver("0.0.1+1"); + fixture.AssertFullSemver("0.0.1-1"); } [Test] @@ -204,7 +204,7 @@ public void EnsurePreReleaseTagLabelWillBeConsideredIfNoLabelIsDefined(long patc fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1+1", configuration); fixture.ApplyTag($"0.0.{patchNumber}-alpha.1"); @@ -249,7 +249,7 @@ public void EnsurePreReleaseTagLabelWillBeConsideredIfNoLabelIsDefined(long patc fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber + 1}+1", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber + 1}-1+1", configuration); fixture.Repository.DumpGraph(); } @@ -270,52 +270,52 @@ public void EnsurePreReleaseTagLabelWithInitialTagForPatchNumberOneWillBeConside fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1+1", configuration); - fixture.ApplyTag($"1.0.1-alpha.1"); + fixture.ApplyTag("1.0.1-alpha.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-alpha.1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+2", configuration); + fixture.AssertFullSemver("1.0.1-alpha.2+1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+3", configuration); + fixture.AssertFullSemver("1.0.1-alpha.2+2", configuration); - fixture.MakeATaggedCommit($"1.0.1-beta.1"); + fixture.MakeATaggedCommit("1.0.1-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+4", configuration); + fixture.AssertFullSemver("1.0.1-beta.1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+5", configuration); + fixture.AssertFullSemver("1.0.1-beta.2+1", configuration); - fixture.MakeATaggedCommit($"1.0.1-beta.2"); + fixture.MakeATaggedCommit("1.0.1-beta.2"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+6", configuration); + fixture.AssertFullSemver("1.0.1-beta.2", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1+7", configuration); + fixture.AssertFullSemver("1.0.1-beta.3+1", configuration); - fixture.ApplyTag($"1.0.1"); + fixture.ApplyTag("1.0.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.1", configuration); + fixture.AssertFullSemver("1.0.1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.2+1", configuration); + fixture.AssertFullSemver("1.0.2-1+1", configuration); fixture.Repository.DumpGraph(); } @@ -337,7 +337,7 @@ public void EnsurePreReleaseTagLabelWithInitialTagForPatchNumberTwoAndThreeWillB fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1+1", configuration); fixture.ApplyTag($"1.0.{patchNumber}-alpha.1"); @@ -382,7 +382,7 @@ public void EnsurePreReleaseTagLabelWithInitialTagForPatchNumberTwoAndThreeWillB fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber + 1}+1", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber + 1}-1+1", configuration); fixture.Repository.DumpGraph(); } @@ -403,42 +403,42 @@ public void EnsurePreReleaseTagLabelWillBeConsideredIfLabelIsEmpty(long patchNum fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1+1", configuration); fixture.ApplyTag($"0.0.{patchNumber}-alpha.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+1", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+2", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+2", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+3", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+3", configuration); fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+4", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+4", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+5", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+5", configuration); fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.2"); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+6", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+6", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber}+7", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber}-1+7", configuration); fixture.ApplyTag($"0.0.{patchNumber}"); @@ -448,7 +448,7 @@ public void EnsurePreReleaseTagLabelWillBeConsideredIfLabelIsEmpty(long patchNum fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"0.0.{patchNumber + 1}+1", configuration); + fixture.AssertFullSemver($"0.0.{patchNumber + 1}-1+1", configuration); } [TestCase(1)] @@ -468,42 +468,42 @@ public void EnsurePreReleaseTagLabelWithInitialTagWillBeConsideredIfLabelIsEmpty fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.1+1", configuration); + fixture.AssertFullSemver("1.0.1-1+1", configuration); fixture.ApplyTag($"1.0.{patchNumber}-alpha.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+1", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+1", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+2", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+2", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+3", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+3", configuration); fixture.MakeATaggedCommit($"1.0.{patchNumber}-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+4", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+4", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+5", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+5", configuration); fixture.MakeATaggedCommit($"1.0.{patchNumber}-beta.2"); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+6", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+6", configuration); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber}+7", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber}-1+7", configuration); fixture.ApplyTag($"1.0.{patchNumber}"); @@ -513,7 +513,7 @@ public void EnsurePreReleaseTagLabelWithInitialTagWillBeConsideredIfLabelIsEmpty fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver($"1.0.{patchNumber + 1}+1", configuration); + fixture.AssertFullSemver($"1.0.{patchNumber + 1}-1+1", configuration); } [TestCase(1)] @@ -919,6 +919,7 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd .WithVersioningMode(VersioningMode.ContinuousDeployment) .WithIncrement(IncrementStrategy.None) .WithLabel(label) + .WithIsMainline(false) ) .Build(); @@ -926,12 +927,12 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("0.0.0", configuration); + fixture.AssertFullSemver("0.0.0-1", configuration); fixture.MakeACommit("+semver: minor"); // ✅ succeeds as expected - fixture.AssertFullSemver("0.1.0", configuration); + fixture.AssertFullSemver("0.1.0-2", configuration); fixture.ApplyTag("1.0.0"); @@ -941,13 +942,13 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd fixture.MakeACommit("+semver: major"); // ✅ succeeds as expected - fixture.AssertFullSemver("2.0.0", configuration); + fixture.AssertFullSemver("2.0.0-1", configuration); fixture.ApplyTag("2.0.0"); fixture.MakeACommit(); // ✅ succeeds as expected - fixture.AssertFullSemver("2.0.0", configuration); + fixture.AssertFullSemver("2.0.0-1", configuration); } [Test] @@ -959,6 +960,7 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd .WithVersioningMode(VersioningMode.ContinuousDeployment) .WithIncrement(IncrementStrategy.None) .WithLabel("pre") + .WithIsMainline(false) ).Build(); using var fixture = new EmptyRepositoryFixture("main"); @@ -999,6 +1001,7 @@ public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTag .WithLabel("beta") .WithIncrement(IncrementStrategy.Patch) .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithIsMainline(false) ).Build(); using EmptyRepositoryFixture fixture = new("main"); @@ -1027,4 +1030,24 @@ public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTag // ✅ succeeds as expected fixture.AssertFullSemver("5.0.0-beta.5", configuration); } + + /// + /// https://github.com/GitTools/GitVersion/issues/2347 + /// + [Test] + public void EnsureThePreReleaseTagIsCorrectlyGeneratedWhenPreReleaseLabelIsEmpty() + { + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", _ => _ + .WithLabel(string.Empty).WithIsMainline(false) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + ).Build(); + + using var fixture = new EmptyRepositoryFixture("main"); + fixture.Repository.MakeCommits(5); + + var variables = fixture.GetVersion(configuration); + + fixture.AssertFullSemver("0.0.1-5", configuration); + } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs index 8023c895b6..b4d50551d1 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -1,7 +1,6 @@ using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Extensions; -using GitVersion.VersionCalculation; using LibGit2Sharp; namespace GitVersion.Core.Tests.IntegrationTests; @@ -154,9 +153,9 @@ public void WhenReleaseBranchOffDevelopIsMergedIntoMainAndDevelopVersionIsTakenW fixture.Checkout(MainBranch); fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); fixture.Repository.MakeCommits(2); - fixture.AssertFullSemver("2.0.0+2"); + fixture.AssertFullSemver("2.0.0-2"); } [Test] @@ -171,7 +170,7 @@ public void WhenReleaseBranchOffMainIsMergedIntoMainVersionIsTakenWithIt() fixture.Checkout(MainBranch); fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); } [Test] @@ -186,12 +185,12 @@ public void MainVersioningContinuousCorrectlyAfterMergingReleaseBranch() fixture.Checkout(MainBranch); fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); fixture.Repository.Branches.Remove("release-2.0.0"); - fixture.AssertFullSemver("2.0.0+0"); + fixture.AssertFullSemver("2.0.0-0"); fixture.Repository.ApplyTag("2.0.0"); fixture.Repository.MakeCommits(1); - fixture.AssertFullSemver("2.0.1+1"); + fixture.AssertFullSemver("2.0.1-1"); } [Test] @@ -236,7 +235,7 @@ public void WhenReleaseBranchIsMergedIntoMainHighestVersionIsTakenWithIt() fixture.Checkout(MainBranch); fixture.Repository.MergeNoFF("release-1.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.0.0+5"); + fixture.AssertFullSemver("2.0.0-5"); } [Test] @@ -264,7 +263,7 @@ public void WhenReleaseBranchIsMergedIntoMainHighestVersionIsTakenWithItEvenWith fixture.Checkout(MainBranch); fixture.Repository.MergeNoFF("release-1.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("3.0.0+10"); + fixture.AssertFullSemver("3.0.0-10"); } [Test] @@ -306,9 +305,7 @@ public void WhenMergingReleaseBackToDevShouldNotResetBetaVersion() [Test] public void HotfixOffReleaseBranchShouldNotResetCount() { - var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .Build(); + var configuration = GitFlowConfigurationBuilder.New.Build(); using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); @@ -321,12 +318,12 @@ public void HotfixOffReleaseBranchShouldNotResetCount() fixture.Checkout("release-2.0.0"); fixture.Repository.MakeCommits(1); - fixture.AssertFullSemver("2.0.0-beta.1", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+1", configuration); //tag it to bump to beta 2 fixture.Repository.MakeCommits(4); - fixture.AssertFullSemver("2.0.0-beta.5", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+5", configuration); //merge down to develop fixture.Repository.CreateBranch("hotfix-2.0.0"); @@ -336,7 +333,7 @@ public void HotfixOffReleaseBranchShouldNotResetCount() fixture.Checkout("release-2.0.0"); fixture.Repository.MergeNoFF("hotfix-2.0.0", Generate.SignatureNow()); fixture.Repository.Branches.Remove(fixture.Repository.Branches["hotfix-2.0.0"]); - fixture.AssertFullSemver("2.0.0-beta.7", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+7", configuration); } [Test] @@ -344,7 +341,6 @@ public void MergeOnReleaseBranchShouldNotResetCount() { var configuration = GitFlowConfigurationBuilder.New .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) - .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -359,22 +355,20 @@ public void MergeOnReleaseBranchShouldNotResetCount() fixture.Repository.CreateBranch("release/2.0.0-xxx"); fixture.Checkout("release/2.0.0-xxx"); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("2.0.0-beta.1", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+1", configuration); fixture.Checkout("release/2.0.0"); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("2.0.0-beta.1", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+1", configuration); fixture.Repository.MergeNoFF("release/2.0.0-xxx"); - fixture.AssertFullSemver("2.0.0-beta.2", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+2", configuration); } [Test] public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() { - var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .Build(); + var configuration = GitFlowConfigurationBuilder.New.Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit("initial"); @@ -382,12 +376,12 @@ public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() // Create release from develop fixture.BranchTo("release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.0", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+0", configuration); // Make some commits on release fixture.MakeACommit("release 1"); fixture.MakeACommit("release 2"); - fixture.AssertFullSemver("2.0.0-beta.2", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+2", configuration); // First forward merge release to develop fixture.Checkout("develop"); @@ -396,24 +390,24 @@ public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() // Make some new commit on release fixture.Checkout("release-2.0.0"); fixture.Repository.MakeACommit("release 3 - after first merge"); - fixture.AssertFullSemver("2.0.0-beta.3", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+3", configuration); // Make new commit on develop fixture.Checkout("develop"); // Checkout to release (no new commits) fixture.Checkout("release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.3", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+3", configuration); fixture.Checkout("develop"); fixture.Repository.MakeACommit("develop after merge"); // Checkout to release (no new commits) fixture.Checkout("release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.3", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+3", configuration); // Make some new commit on release fixture.Repository.MakeACommit("release 4"); fixture.Repository.MakeACommit("release 5"); - fixture.AssertFullSemver("2.0.0-beta.5", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+5", configuration); // Second merge release to develop fixture.Checkout("develop"); @@ -421,15 +415,13 @@ public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() // Checkout to release (no new commits) fixture.Checkout("release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.5", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+5", configuration); } [Test] public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount() { - var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .Build(); + var configuration = GitFlowConfigurationBuilder.New.Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("initial"); @@ -437,12 +429,12 @@ public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount() Commands.Checkout(fixture.Repository, "develop"); fixture.Repository.CreateBranch("release-2.0.0"); Commands.Checkout(fixture.Repository, "release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.0", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+0", configuration); // Make some commits on release var commit1 = fixture.Repository.MakeACommit(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("2.0.0-beta.2", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+2", configuration); // Merge release to develop - emulate commit between other person release commit push and this commit merge to develop Commands.Checkout(fixture.Repository, "develop"); @@ -451,12 +443,12 @@ public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount() // Check version on release after merge to develop Commands.Checkout(fixture.Repository, "release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.2", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+2", configuration); // Check version on release after making some new commits fixture.Repository.MakeACommit(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("2.0.0-beta.4", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+4", configuration); } [Test] @@ -503,9 +495,7 @@ public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion() [Test] public void FeatureFromReleaseBranchShouldNotResetCount() { - var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.ContinuousDeployment) - .Build(); + var configuration = GitFlowConfigurationBuilder.New.Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("initial"); @@ -513,11 +503,11 @@ public void FeatureFromReleaseBranchShouldNotResetCount() Commands.Checkout(fixture.Repository, "develop"); fixture.Repository.CreateBranch("release-2.0.0"); Commands.Checkout(fixture.Repository, "release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.0", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+0", configuration); // Make some commits on release fixture.Repository.MakeCommits(10); - fixture.AssertFullSemver("2.0.0-beta.10", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+10", configuration); // Create feature from release fixture.BranchTo("feature/xxx"); @@ -526,9 +516,9 @@ public void FeatureFromReleaseBranchShouldNotResetCount() // Check version on release Commands.Checkout(fixture.Repository, "release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.10", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+10", configuration); fixture.Repository.MakeACommit("release 11"); - fixture.AssertFullSemver("2.0.0-beta.11", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+11", configuration); // Make new commit on feature Commands.Checkout(fixture.Repository, "feature/xxx"); @@ -536,14 +526,14 @@ public void FeatureFromReleaseBranchShouldNotResetCount() // Checkout to release (no new commits) Commands.Checkout(fixture.Repository, "release-2.0.0"); - fixture.AssertFullSemver("2.0.0-beta.11", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+11", configuration); // Merge feature to release fixture.Repository.MergeNoFF("feature/xxx", Generate.SignatureNow()); - fixture.AssertFullSemver("2.0.0-beta.15", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+15", configuration); fixture.Repository.MakeACommit("release 13 - after feature merge"); - fixture.AssertFullSemver("2.0.0-beta.16", configuration); + fixture.AssertFullSemver("2.0.0-beta.1+16", configuration); } [Test] @@ -588,7 +578,6 @@ public void FeatureOnReleaseFeatureBranchDeleted() { var configuration = GitFlowConfigurationBuilder.New .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) - .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -602,7 +591,7 @@ public void FeatureOnReleaseFeatureBranchDeleted() // begin the release branch fixture.Repository.CreateBranch(release450); Commands.Checkout(fixture.Repository, release450); - fixture.AssertFullSemver("4.5.0-beta.0", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+0", configuration); fixture.Repository.CreateBranch(featureBranch); Commands.Checkout(fixture.Repository, featureBranch); @@ -611,7 +600,7 @@ public void FeatureOnReleaseFeatureBranchDeleted() fixture.Repository.MergeNoFF(featureBranch, Generate.SignatureNow()); // commit 2 fixture.Repository.Branches.Remove(featureBranch); - fixture.AssertFullSemver("4.5.0-beta.2", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+2", configuration); } /// @@ -622,7 +611,6 @@ public void FeatureOnReleaseFeatureBranchNotDeleted() { var configuration = GitFlowConfigurationBuilder.New .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) - .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -636,7 +624,7 @@ public void FeatureOnReleaseFeatureBranchNotDeleted() // begin the release branch fixture.Repository.CreateBranch(release450); Commands.Checkout(fixture.Repository, release450); - fixture.AssertFullSemver("4.5.0-beta.0", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+0", configuration); fixture.Repository.CreateBranch(featureBranch); Commands.Checkout(fixture.Repository, featureBranch); @@ -644,7 +632,7 @@ public void FeatureOnReleaseFeatureBranchNotDeleted() Commands.Checkout(fixture.Repository, release450); fixture.Repository.MergeNoFF(featureBranch, Generate.SignatureNow()); // commit 2 - fixture.AssertFullSemver("4.5.0-beta.2", configuration); + fixture.AssertFullSemver("4.5.0-beta.1+2", configuration); } [TestCase("release/1.2.0", "1.2.0-beta.1+1", SemanticVersionFormat.Loose)] diff --git a/src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs index 21f2dd8a39..7adbe74f07 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs @@ -13,8 +13,8 @@ public class RemoteRepositoryScenarios : TestBase public void GivenARemoteGitRepositoryWithCommitsThenClonedLocalShouldMatchRemoteVersion() { using var fixture = new RemoteRepositoryFixture(); - fixture.AssertFullSemver("0.0.1+5"); - fixture.AssertFullSemver("0.0.1+5", repository: fixture.LocalRepositoryFixture.Repository); + fixture.AssertFullSemver("0.0.1-5"); + fixture.AssertFullSemver("0.0.1-5", repository: fixture.LocalRepositoryFixture.Repository); } [Test] @@ -76,11 +76,11 @@ public void GivenARemoteGitRepositoryAheadOfLocalRepositoryThenChangesShouldPull { using var fixture = new RemoteRepositoryFixture(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("0.0.1+6"); - fixture.AssertFullSemver("0.0.1+5", repository: fixture.LocalRepositoryFixture.Repository); + fixture.AssertFullSemver("0.0.1-6"); + fixture.AssertFullSemver("0.0.1-5", repository: fixture.LocalRepositoryFixture.Repository); var buildSignature = fixture.LocalRepositoryFixture.Repository.Config.BuildSignature(new DateTimeOffset(DateTime.Now)); Commands.Pull(fixture.LocalRepositoryFixture.Repository, buildSignature, new PullOptions()); - fixture.AssertFullSemver("0.0.1+6", repository: fixture.LocalRepositoryFixture.Repository); + fixture.AssertFullSemver("0.0.1-6", repository: fixture.LocalRepositoryFixture.Repository); } [Test] diff --git a/src/GitVersion.Core.Tests/IntegrationTests/SupportBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/SupportBranchScenarios.cs index 42c4431f6c..8c41ca6f20 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/SupportBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/SupportBranchScenarios.cs @@ -36,10 +36,10 @@ public void SupportIsCalculatedCorrectly() fixture.AssertFullSemver("1.2.0-beta.1+1"); // Create 1.2.0 release - fixture.Checkout("support/1.0.0"); - fixture.MergeNoFF("release/1.2.0"); - fixture.AssertFullSemver("1.2.0+0"); - fixture.ApplyTag("1.2.0"); + Commands.Checkout(fixture.Repository, "support/1.0.0"); + fixture.Repository.MergeNoFF("release/1.2.0"); + fixture.AssertFullSemver("1.2.0-0"); + fixture.Repository.ApplyTag("1.2.0"); // Create 1.2.1 hotfix fixture.BranchTo("hotfix/1.2.1"); @@ -47,7 +47,7 @@ public void SupportIsCalculatedCorrectly() fixture.AssertFullSemver("1.2.1-beta.1+3"); fixture.Checkout("support/1.0.0"); fixture.MergeNoFF("hotfix/1.2.1"); - fixture.AssertFullSemver("1.2.1+2"); + fixture.AssertFullSemver("1.2.1-2"); } [Test] @@ -68,7 +68,7 @@ public void WhenSupportIsBranchedAndTaggedFromAnotherSupportEnsureNewMinorIsUsed fixture.Repository.MakeACommit(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.3.1+2"); + fixture.AssertFullSemver("1.3.1-2"); } [Test] @@ -79,13 +79,13 @@ public void WhenSupportIsBranchedFromMainWithSpecificTag() using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); - fixture.AssertFullSemver("0.0.1+1"); + fixture.AssertFullSemver("0.0.1-1"); fixture.ApplyTag("1.4.0-rc"); fixture.MakeACommit(); fixture.BranchTo("support/1"); - fixture.AssertFullSemver("1.4.0+2", configuration); + fixture.AssertFullSemver("1.4.0-2", configuration); } [Test] @@ -96,11 +96,11 @@ public void WhenSupportIsBranchedFromMainWithSpecificTagOnCommit() using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); - fixture.AssertFullSemver("0.0.1+1", configuration); + fixture.AssertFullSemver("0.0.1-1", configuration); fixture.ApplyTag("1.4.0-rc"); fixture.BranchTo("support/1"); - fixture.AssertFullSemver("1.4.0+1", configuration); + fixture.AssertFullSemver("1.4.0-1", configuration); } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs index 3310775525..ec91cc6f8f 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs @@ -20,7 +20,7 @@ public void AppliedPreReleaseLabelCausesBump() fixture.Repository.MakeATaggedCommit("1.0.0-pre.1"); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.0.0-pre.2+1", configuration); + fixture.AssertFullSemver("1.0.0-pre.2", configuration); } [Test] @@ -31,11 +31,11 @@ public void CanUseCommitMessagesToBumpVersion() fixture.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeACommit("+semver:minor"); - fixture.AssertFullSemver("1.1.0+1"); + fixture.AssertFullSemver("1.1.0-1"); fixture.Repository.MakeACommit("+semver:major"); - fixture.AssertFullSemver("2.0.0+2"); + fixture.AssertFullSemver("2.0.0-2"); } [Test] @@ -46,13 +46,13 @@ public void CanUseCommitMessagesToBumpVersion_TagTakesPriority() repo.MakeATaggedCommit("1.0.0"); repo.MakeACommit("+semver:major"); - fixture.AssertFullSemver("2.0.0+1"); + fixture.AssertFullSemver("2.0.0-1"); repo.ApplyTag("1.1.0"); fixture.AssertFullSemver("1.1.0"); repo.MakeACommit(); - fixture.AssertFullSemver("1.1.1+1"); + fixture.AssertFullSemver("1.1.1-1"); } [Theory] @@ -105,7 +105,7 @@ public void CanUseCommitMessagesToBumpVersionBaseVersionTagIsAppliedToSameCommit fixture.Repository.MakeACommit(); fixture.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeACommit("+semver:minor"); - fixture.AssertFullSemver("1.1.0+1"); + fixture.AssertFullSemver("1.1.0-1"); fixture.ApplyTag("2.0.0"); @@ -113,6 +113,6 @@ public void CanUseCommitMessagesToBumpVersionBaseVersionTagIsAppliedToSameCommit // Default bump is patch - fixture.AssertFullSemver("2.0.1+1"); + fixture.AssertFullSemver("2.0.1-1"); } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs index 1944952d6e..cb1bc4853d 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs @@ -35,7 +35,7 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig() using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); fixture.BranchTo("support/2.0.0"); - fixture.AssertFullSemver("2.0.0+1", configuration); + fixture.AssertFullSemver("2.0.0-1", configuration); } [Test] diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs index 39ca78f3c2..44cf5412a4 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs @@ -38,7 +38,7 @@ public void DoesNotTakeVersionFromBranchWithAccidentalVersion(string branch) fixture.Checkout("main"); fixture.MergeNoFF($"{branch}/downgrade-some-lib-to-3.2.1"); - fixture.AssertFullSemver("1.0.1+2"); + fixture.AssertFullSemver("1.0.1-2"); } [Test] @@ -64,7 +64,7 @@ public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin() fixture.LocalRepositoryFixture.MergeNoFF("origin/release/2.0.0"); - fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0+0"); + fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-0"); } [Test] @@ -78,7 +78,7 @@ public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote() fixture.LocalRepositoryFixture.MergeNoFF("upstream/release/2.0.0"); - fixture.LocalRepositoryFixture.AssertFullSemver("0.0.1+7"); + fixture.LocalRepositoryFixture.AssertFullSemver("0.0.1-7"); } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs index e78ff17810..09dd5e13ba 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs @@ -1,6 +1,5 @@ using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; -using GitVersion.VersionCalculation; namespace GitVersion.Core.Tests.IntegrationTests; @@ -49,7 +48,6 @@ public void LabelPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedP var configuration = GitFlowConfigurationBuilder.New .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") .WithLabelPreReleaseWeight(65535) - .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); // Act @@ -60,7 +58,7 @@ public void LabelPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedP fixture.MakeACommit("Feature commit 1"); fixture.BranchTo("release/1.1.0"); fixture.MakeACommit("Release commit 1"); - fixture.AssertFullSemver("1.1.0-beta.1", configuration); + fixture.AssertFullSemver("1.1.0-beta.1+1", configuration); fixture.Checkout("main"); fixture.MergeNoFF("release/1.1.0"); @@ -77,7 +75,6 @@ public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_Weighted // Arrange var configuration = GitFlowConfigurationBuilder.New .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") - .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); // Act @@ -88,7 +85,7 @@ public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_Weighted fixture.MakeACommit("Feature commit 1"); fixture.BranchTo("release/1.1.0"); fixture.MakeACommit("Release commit 1"); - fixture.AssertFullSemver("1.1.0-beta.1", configuration); + fixture.AssertFullSemver("1.1.0-beta.1+1", configuration); fixture.Checkout("main"); fixture.MergeNoFF("release/1.1.0"); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLabel.approved.txt b/src/GitVersion.Core.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLabel.approved.txt new file mode 100644 index 0000000000..f6bd57ef8f --- /dev/null +++ b/src/GitVersion.Core.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLabel.approved.txt @@ -0,0 +1,27 @@ +{ + "AssemblySemFileVer": "1.2.3.0", + "AssemblySemVer": "1.2.3.0", + "BranchName": "main", + "BuildMetaData": null, + "CommitDate": "2014-03-06", + "CommitsSinceVersionSource": 5, + "EscapedBranchName": "main", + "FullBuildMetaData": "Branch.main.Sha.commitSha", + "FullSemVer": "1.2.3-9", + "InformationalVersion": "1.2.3-9+Branch.main.Sha.commitSha", + "Major": 1, + "MajorMinorPatch": "1.2.3", + "Minor": 2, + "Patch": 3, + "PreReleaseLabel": "", + "PreReleaseLabelWithDash": "", + "PreReleaseNumber": 9, + "PreReleaseTag": "9", + "PreReleaseTagWithDash": "-9", + "SemVer": "1.2.3-9", + "Sha": "commitSha", + "ShortSha": "commitShortSha", + "UncommittedChanges": 0, + "VersionSourceSha": "versionSourceSha", + "WeightedPreReleaseNumber": 55009 +} \ No newline at end of file diff --git a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs index a6375f4daf..e98743b8ac 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -1,528 +1,570 @@ -using GitVersion.Common; -using GitVersion.Configuration; -using GitVersion.Core.Tests.Helpers; -using GitVersion.Core.Tests.IntegrationTests; -using GitVersion.Logging; -using GitVersion.VersionCalculation; -using LibGit2Sharp; -using Microsoft.Extensions.DependencyInjection; - -namespace GitVersion.Core.Tests.VersionCalculation; - -public class NextVersionCalculatorTests : TestBase -{ - [Test] - public void ShouldIncrementVersionBasedOnConfig() - { - var contextBuilder = new GitVersionContextBuilder(); - - contextBuilder.Build(); - - contextBuilder.ServicesProvider.ShouldNotBeNull(); - var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); - nextVersionCalculator.ShouldNotBeNull(); - - var nextVersion = nextVersionCalculator.FindVersion(); - - nextVersion.IncrementedVersion.ToString().ShouldBe("0.0.1"); - } - - [Test] - public void DoesNotIncrementWhenBaseVersionSaysNotTo() - { - var contextBuilder = new GitVersionContextBuilder(); - - var overrideConfiguration = new Dictionary() - { - { "next-version", "1.0.0" } - }; - contextBuilder.WithOverrideConfiguration(overrideConfiguration).Build(); - - contextBuilder.ServicesProvider.ShouldNotBeNull(); - var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); - - nextVersionCalculator.ShouldNotBeNull(); - - var nextVersion = nextVersionCalculator.FindVersion(); - - nextVersion.IncrementedVersion.ToString().ShouldBe("1.0.0"); - } - - [Test] - public void AppliesBranchPreReleaseTag() - { - var contextBuilder = new GitVersionContextBuilder(); - - contextBuilder.WithDevelopBranch().Build(); - - contextBuilder.ServicesProvider.ShouldNotBeNull(); - var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); - nextVersionCalculator.ShouldNotBeNull(); - - var nextVersion = nextVersionCalculator.FindVersion(); - - nextVersion.IncrementedVersion.ToString("f").ShouldBe("0.1.0-alpha.1+0"); - } - - [Test] - public void PreReleaseLabelCanUseBranchName() - { - var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0") - .WithBranch("custom", builder => builder - .WithRegularExpression("custom/") - .WithLabel(ConfigurationConstants.BranchNamePlaceholder) - .WithSourceBranches() - ) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.BranchTo("develop"); - fixture.MakeACommit(); - fixture.BranchTo("custom/foo"); - fixture.MakeACommit(); - - fixture.AssertFullSemver("1.0.0-foo.1+3", configuration); - } - - [Test] - public void PreReleaseVersionMainline() - { - var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0") - .WithBranch("unknown", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.BranchTo("foo"); - fixture.MakeACommit(); - - fixture.AssertFullSemver("1.0.0-foo.1", configuration); - } - - [Test] - public void MergeIntoMainline() - { - var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0") - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.BranchTo("foo"); - fixture.MakeACommit(); - fixture.Checkout(MainBranch); - fixture.MergeNoFF("foo"); - - fixture.AssertFullSemver("1.0.0", configuration); - } - - [Test] - public void MergeFeatureIntoMainline() - { - var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.ApplyTag("1.0.0"); - fixture.AssertFullSemver("1.0.0", configuration); - - fixture.BranchTo("feature/foo"); - fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.1-foo.1", configuration); - fixture.ApplyTag("1.0.1-foo.1"); - - fixture.Checkout(MainBranch); - fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.0.1", configuration); - } - - [Test] - public void MergeFeatureIntoMainlineWithMinorIncrement() - { - var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .WithBranch("feature", builder => builder - .WithVersioningMode(VersioningMode.Mainline) - .WithIncrement(IncrementStrategy.Minor) - ) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.ApplyTag("1.0.0"); - fixture.AssertFullSemver("1.0.0", configuration); - - fixture.BranchTo("feature/foo"); - fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.0-foo.1", configuration); - fixture.ApplyTag("1.1.0-foo.1"); - - fixture.Checkout(MainBranch); - fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.1.0", configuration); - } - - [Test] - public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix() - { - var configuration = GitFlowConfigurationBuilder.New - .WithVersioningMode(VersioningMode.Mainline) - .WithBranch("feature", builder => builder - .WithIncrement(IncrementStrategy.Minor) - .WithVersioningMode(VersioningMode.Mainline)) - .WithBranch("hotfix", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.ApplyTag("1.0.0"); - fixture.AssertFullSemver("1.0.0", configuration); - - fixture.BranchTo("feature/foo"); - fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.0-foo.1", configuration); - fixture.ApplyTag("1.1.0-foo.1"); - - fixture.Checkout(MainBranch); - fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.1.0", configuration); - fixture.ApplyTag("1.1.0"); - - fixture.BranchTo("hotfix/bar"); - fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.1-beta.1", configuration); - fixture.ApplyTag("1.1.1-beta.1"); - - fixture.Checkout(MainBranch); - fixture.MergeNoFF("hotfix/bar"); - fixture.AssertFullSemver("1.1.1", configuration); - } - - [Test] - public void PreReleaseLabelCanUseBranchNameVariable() - { - var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0") - .WithBranch("custom", builder => builder - .WithRegularExpression("custom/") - .WithLabel($"alpha.{ConfigurationConstants.BranchNamePlaceholder}") - .WithSourceBranches() - ) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - fixture.BranchTo("develop"); - fixture.MakeACommit(); - fixture.BranchTo("custom/foo"); - fixture.MakeACommit(); - - fixture.AssertFullSemver("1.0.0-alpha.foo.1+3", configuration); - } - - [Test] - public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery() - { - var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithLabel("beta")) - .WithBranch("feature", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDelivery) - ) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit(); - - fixture.BranchTo("feature/test"); - fixture.MakeATaggedCommit("0.1.0-test.1"); - fixture.MakeACommit(); - - fixture.AssertFullSemver("0.1.0-test.2+1", configuration); - - fixture.Checkout("main"); - fixture.Repository.Merge("feature/test", Generate.SignatureNow()); - - fixture.AssertFullSemver("0.1.0-beta.1+3", configuration); - } - - [Test] - public void GetNextVersionOnNonMainlineBranchWithoutCommitsShouldWorkNormally() - { - var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0") - .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - - using var fixture = new EmptyRepositoryFixture(); - fixture.MakeACommit("initial commit"); - fixture.BranchTo("feature/f1"); - fixture.AssertFullSemver("1.0.0-f1.0", configuration); - } - - [Test] - public void ChoosesHighestVersionReturnedFromStrategies() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var dateTimeOffset = DateTimeOffset.Now; - var versionStrategies = new IVersionStrategy[] { new V1Strategy(DateTimeOffset.Now), new V2Strategy(dateTimeOffset) }; - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); - nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); - nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); - nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(dateTimeOffset); - } - - [Test] - public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhen() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var when = DateTimeOffset.Now; - var versionStrategies = new IVersionStrategy[] { new V1Strategy(when), new V2Strategy(null) }; - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); - nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); - nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); - nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(when); - } - - [Test] - public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhenReversedOrder() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var when = DateTimeOffset.Now; - var versionStrategies = new IVersionStrategy[] { new V2Strategy(null), new V1Strategy(when) }; - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); - nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); - nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); - nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(when); - } - - [Test] - public void ShouldNotFilterVersion() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var version = new BaseVersion("dummy", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null); - var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(version) }; - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.Source.ShouldBe(version.Source); - nextVersion.BaseVersion.ShouldIncrement.ShouldBe(version.ShouldIncrement); - nextVersion.BaseVersion.SemanticVersion.ShouldBe(version.SemanticVersion); - } - - [Test] - public void ShouldFilterVersion() - { - // Arrange - var commitToExclude = GitToolsTestingExtensions.CreateMockCommit(); - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var ignoreConfiguration = IgnoreConfigurationBuilder.New.WithShas(commitToExclude.Sha).Build(); - var configuration = GitFlowConfigurationBuilder.New.WithIgnoreConfiguration(ignoreConfiguration).Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), commitToExclude, null); - var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); - var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(higherVersion, lowerVersion) }; - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.Source.ShouldNotBe(higherVersion.Source); - nextVersion.BaseVersion.SemanticVersion.ShouldNotBe(higherVersion.SemanticVersion); - nextVersion.BaseVersion.Source.ShouldBe(lowerVersion.Source); - nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); - } - - [Test] - public void ShouldIgnorePreReleaseVersionInMainlineMode() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) - .Build(); - var context = new GitVersionContext(branchMock, null, configuration, null, 0); - var repositoryStoreMock = Substitute.For(); - var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); - var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); - var effectiveBranchConfigurationFinderMock = Substitute.For(); - effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); - var incrementStrategyFinderMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); - var preReleaseVersion = new BaseVersion( - "prerelease", - false, - new SemanticVersion(1, 0, 1) - { - PreReleaseTag = new SemanticVersionPreReleaseTag - { - Name = "alpha", - Number = 1 - } - }, - GitToolsTestingExtensions.CreateMockCommit(), - null - ); - var mainlineVersionCalculatorMock = Substitute.For(); - mainlineVersionCalculatorMock.FindMainlineModeVersion(Arg.Any()).Returns(lowerVersion.SemanticVersion); - var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(preReleaseVersion, lowerVersion) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, - repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); - - // Act - var nextVersion = unitUnderTest.FindVersion(); - - // Assert - nextVersion.BaseVersion.Source.ShouldNotBe(preReleaseVersion.Source); - nextVersion.BaseVersion.SemanticVersion.ShouldNotBe(preReleaseVersion.SemanticVersion); - nextVersion.BaseVersion.Source.ShouldBe(lowerVersion.Source); - nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); - } - - private sealed class V1Strategy : IVersionStrategy - { - private readonly ICommit? when; - - public V1Strategy(DateTimeOffset? when) - { - if (when != null) - { - this.when = GitToolsTestingExtensions.CreateMockCommit(); - this.when.When.Returns(when.Value); - } - else - { - this.when = null; - } - } - - public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) - { - yield return new BaseVersion("Source 1", false, new SemanticVersion(1), this.when, null); - } - } - - private sealed class V2Strategy : IVersionStrategy - { - private readonly ICommit? when; - - public V2Strategy(DateTimeOffset? when) - { - if (when != null) - { - this.when = GitToolsTestingExtensions.CreateMockCommit(); - this.when.When.Returns(when.Value); - } - else - { - this.when = null; - } - } - - public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) - { - yield return new BaseVersion("Source 2", true, new SemanticVersion(2), this.when, null); - } - } - - private sealed class TestVersionStrategy : IVersionStrategy - { - private readonly IEnumerable baseVersions; - - public TestVersionStrategy(params BaseVersion[] baseVersions) => this.baseVersions = baseVersions; - - public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) => this.baseVersions; - } -} +//using GitVersion.Common; +//using GitVersion.Configuration; +//using GitVersion.Core.Tests.Helpers; +//using GitVersion.Core.Tests.IntegrationTests; +//using GitVersion.Logging; +//using GitVersion.VersionCalculation; +//using LibGit2Sharp; +//using Microsoft.Extensions.DependencyInjection; + +//namespace GitVersion.Core.Tests.VersionCalculation; + +//public class NextVersionCalculatorTests : TestBase +//{ +// [Test] +// public void ShouldIncrementVersionBasedOnConfig() +// { +// var contextBuilder = new GitVersionContextBuilder(); + +// contextBuilder.Build(); + +// contextBuilder.ServicesProvider.ShouldNotBeNull(); +// var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); +// nextVersionCalculator.ShouldNotBeNull(); + +// var nextVersion = nextVersionCalculator.FindVersion(); + +// nextVersion.IncrementedVersion.ToString().ShouldBe("0.0.1"); +// } + +// [Test] +// public void DoesNotIncrementWhenBaseVersionSaysNotTo() +// { +// var contextBuilder = new GitVersionContextBuilder(); + +// var overrideConfiguration = new Dictionary() +// { +// { "next-version", "1.0.0" } +// }; +// contextBuilder.WithOverrideConfiguration(overrideConfiguration).Build(); + +// contextBuilder.ServicesProvider.ShouldNotBeNull(); +// var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); + +// nextVersionCalculator.ShouldNotBeNull(); + +// var nextVersion = nextVersionCalculator.FindVersion(); + +// nextVersion.IncrementedVersion.ToString().ShouldBe("1.0.0"); +// } + +// [Test] +// public void AppliesBranchPreReleaseTag() +// { +// var contextBuilder = new GitVersionContextBuilder(); + +// contextBuilder.WithDevelopBranch().Build(); + +// contextBuilder.ServicesProvider.ShouldNotBeNull(); +// var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); +// nextVersionCalculator.ShouldNotBeNull(); + +// var nextVersion = nextVersionCalculator.FindVersion(); + +// nextVersion.IncrementedVersion.ToString("f").ShouldBe("0.1.0-alpha.1+0"); +// } + +// [Test] +// public void PreReleaseLabelCanUseBranchName() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithNextVersion("1.0.0") +// .WithBranch("custom", builder => builder +// .WithRegularExpression("custom/") +// .WithLabel(ConfigurationConstants.BranchNamePlaceholder) +// .WithSourceBranches() +// ) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.BranchTo("develop"); +// fixture.MakeACommit(); +// fixture.BranchTo("custom/foo"); +// fixture.MakeACommit(); + +// fixture.AssertFullSemver("1.0.0-foo.1+3", configuration); +// } + +// [Test] +// public void PreReleaseVersionMainline() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithNextVersion("1.0.0") +// .WithBranch("unknown", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.BranchTo("foo"); +// fixture.MakeACommit(); + +// fixture.AssertFullSemver("1.0.0-foo.1", configuration); +// } + +// [Test] +// public void MergeIntoMainline() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithNextVersion("1.0.0") +// .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.BranchTo("foo"); +// fixture.MakeACommit(); +// fixture.Checkout(MainBranch); +// fixture.MergeNoFF("foo"); + +// fixture.AssertFullSemver("1.0.0", configuration); +// } + +// [Test] +// public void MergeFeatureIntoMainline() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.ApplyTag("1.0.0"); +// fixture.AssertFullSemver("1.0.0", configuration); + +// fixture.BranchTo("feature/foo"); +// fixture.MakeACommit(); +// fixture.AssertFullSemver("1.0.1-foo.1", configuration); +// fixture.ApplyTag("1.0.1-foo.1"); + +// fixture.Checkout(MainBranch); +// fixture.MergeNoFF("feature/foo"); +// fixture.AssertFullSemver("1.0.1", configuration); +// } + +// [Test] +// public void MergeFeatureIntoMainlineWithMinorIncrement() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .WithBranch("feature", builder => builder +// .WithVersioningMode(VersioningMode.Mainline) +// .WithIncrement(IncrementStrategy.Minor) +// ) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.ApplyTag("1.0.0"); +// fixture.AssertFullSemver("1.0.0", configuration); + +// fixture.BranchTo("feature/foo"); +// fixture.MakeACommit(); +// fixture.AssertFullSemver("1.1.0-foo.1", configuration); +// fixture.ApplyTag("1.1.0-foo.1"); + +// fixture.Checkout(MainBranch); +// fixture.MergeNoFF("feature/foo"); +// fixture.AssertFullSemver("1.1.0", configuration); +// } + +// [Test] +// public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithVersioningMode(VersioningMode.Mainline) +// .WithBranch("feature", builder => builder +// .WithIncrement(IncrementStrategy.Minor) +// .WithVersioningMode(VersioningMode.Mainline)) +// .WithBranch("hotfix", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.ApplyTag("1.0.0"); +// fixture.AssertFullSemver("1.0.0", configuration); + +// fixture.BranchTo("feature/foo"); +// fixture.MakeACommit(); +// fixture.AssertFullSemver("1.1.0-foo.1", configuration); +// fixture.ApplyTag("1.1.0-foo.1"); + +// fixture.Checkout(MainBranch); +// fixture.MergeNoFF("feature/foo"); +// fixture.AssertFullSemver("1.1.0", configuration); +// fixture.ApplyTag("1.1.0"); + +// fixture.BranchTo("hotfix/bar"); +// fixture.MakeACommit(); +// fixture.AssertFullSemver("1.1.1-beta.1", configuration); +// fixture.ApplyTag("1.1.1-beta.1"); + +// fixture.Checkout(MainBranch); +// fixture.MergeNoFF("hotfix/bar"); +// fixture.AssertFullSemver("1.1.1", configuration); +// } + +// [Test] +// public void PreReleaseLabelCanUseBranchNameVariable() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithNextVersion("1.0.0") +// .WithBranch("custom", builder => builder +// .WithRegularExpression("custom/") +// .WithLabel($"alpha.{ConfigurationConstants.BranchNamePlaceholder}") +// .WithSourceBranches() +// ) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); +// fixture.BranchTo("develop"); +// fixture.MakeACommit(); +// fixture.BranchTo("custom/foo"); +// fixture.MakeACommit(); + +// fixture.AssertFullSemver("1.0.0-alpha.foo.1+3", configuration); +// } + +// [Test] +// public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithBranch("main", builder => builder.WithLabel("beta")) +// .WithBranch("feature", builder => builder +// .WithVersioningMode(VersioningMode.ContinuousDelivery) +// ) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit(); + +// fixture.BranchTo("feature/test"); +// fixture.MakeATaggedCommit("0.1.0-test.1"); +// fixture.MakeACommit(); + +// fixture.AssertFullSemver("0.1.0-test.2+1", configuration); + +// fixture.Checkout("main"); +// fixture.Repository.Merge("feature/test", Generate.SignatureNow()); + +// fixture.AssertFullSemver("0.1.0-beta.1+3", configuration); +// } + +// [Test] +// public void GetNextVersionOnNonMainlineBranchWithoutCommitsShouldWorkNormally() +// { +// var configuration = GitFlowConfigurationBuilder.New +// .WithNextVersion("1.0.0") +// .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); + +// using var fixture = new EmptyRepositoryFixture(); +// fixture.MakeACommit("initial commit"); +// fixture.BranchTo("feature/f1"); +// fixture.AssertFullSemver("1.0.0-f1.0", configuration); +// } + +// [Test] +// public void ChoosesHighestVersionReturnedFromStrategies() +// { +// // Arrange +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var configuration = GitFlowConfigurationBuilder.New.Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var dateTimeOffset = DateTimeOffset.Now; +// var versionStrategies = new IVersionStrategy[] { new V1Strategy(DateTimeOffset.Now), new V2Strategy(dateTimeOffset) }; +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(SemanticVersionBuildMetaData.Empty); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var unitUnderTest = new NextVersionCalculator( +// Substitute.For(), +// mainlineVersionCalculator: mainlineVersionCalculatorMock, +// continuousDeploymentVersionCalculator: continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), +// versionStrategies, effectiveBranchConfigurationFinderMock, +// incrementStrategyFinderMock +// ); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); +// nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); +// nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); +// nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(dateTimeOffset); +// } + +// [Test] +// public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhen() +// { +// // Arrange +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var configuration = GitFlowConfigurationBuilder.New.Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var when = DateTimeOffset.Now; +// var versionStrategies = new IVersionStrategy[] { new V1Strategy(when), new V2Strategy(null) }; +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(SemanticVersionBuildMetaData.Empty); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var unitUnderTest = new NextVersionCalculator( +// Substitute.For(), +// mainlineVersionCalculator: mainlineVersionCalculatorMock, +// continuousDeploymentVersionCalculator: continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), +// versionStrategies, effectiveBranchConfigurationFinderMock, +// incrementStrategyFinderMock +// ); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); +// nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); +// nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); +// nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(when); +// } + +// [Test] +// public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhenReversedOrder() +// { +// // Arrange +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var configuration = GitFlowConfigurationBuilder.New.Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var when = DateTimeOffset.Now; +// var versionStrategies = new IVersionStrategy[] { new V2Strategy(null), new V1Strategy(when) }; +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(SemanticVersionBuildMetaData.Empty); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var unitUnderTest = new NextVersionCalculator( +// Substitute.For(), +// mainlineVersionCalculator: mainlineVersionCalculatorMock, +// continuousDeploymentVersionCalculator: continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), +// versionStrategies, effectiveBranchConfigurationFinderMock, +// incrementStrategyFinderMock +// ); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.SemanticVersion.ToString().ShouldBe("2.0.0"); +// nextVersion.BaseVersion.ShouldIncrement.ShouldBe(true); +// nextVersion.BaseVersion.BaseVersionSource.ShouldNotBeNull(); +// nextVersion.BaseVersion.BaseVersionSource.When.ShouldBe(when); +// } + +// [Test] +// public void ShouldNotFilterVersion() +// { +// // Arrange +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var configuration = GitFlowConfigurationBuilder.New.Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var version = new BaseVersion("dummy", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null); +// var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(version) }; +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(SemanticVersionBuildMetaData.Empty); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var unitUnderTest = new NextVersionCalculator( +// Substitute.For(), +// mainlineVersionCalculator: mainlineVersionCalculatorMock, +// continuousDeploymentVersionCalculator: continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), +// versionStrategies, effectiveBranchConfigurationFinderMock, +// incrementStrategyFinderMock +// ); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.Source.ShouldBe(version.Source); +// nextVersion.BaseVersion.ShouldIncrement.ShouldBe(version.ShouldIncrement); +// nextVersion.BaseVersion.SemanticVersion.ShouldBe(version.SemanticVersion); +// } + +// [Test] +// public void ShouldFilterVersion() +// { +// // Arrange +// var commitToExclude = GitToolsTestingExtensions.CreateMockCommit(); +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var ignoreConfiguration = IgnoreConfigurationBuilder.New.WithShas(commitToExclude.Sha).Build(); +// var configuration = GitFlowConfigurationBuilder.New.WithIgnoreConfiguration(ignoreConfiguration).Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), commitToExclude, null); +// var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); +// var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(higherVersion, lowerVersion) }; +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(SemanticVersionBuildMetaData.Empty); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var unitUnderTest = new NextVersionCalculator( +// Substitute.For(), +// mainlineVersionCalculator: mainlineVersionCalculatorMock, +// continuousDeploymentVersionCalculator: continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), +// versionStrategies, effectiveBranchConfigurationFinderMock, +// incrementStrategyFinderMock +// ); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.Source.ShouldNotBe(higherVersion.Source); +// nextVersion.BaseVersion.SemanticVersion.ShouldNotBe(higherVersion.SemanticVersion); +// nextVersion.BaseVersion.Source.ShouldBe(lowerVersion.Source); +// nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); +// } + +// [Test] +// public void ShouldIgnorePreReleaseVersionInMainlineMode() +// { +// // Arrange +// var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); +// var configuration = GitFlowConfigurationBuilder.New +// .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) +// .Build(); +// var context = new GitVersionContext(branchMock, null, configuration, null, 0); +// var repositoryStoreMock = Substitute.For(); +// var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(branchMock); +// var effectiveBranchConfiguration = new EffectiveBranchConfiguration(branchMock, effectiveConfiguration); +// var effectiveBranchConfigurationFinderMock = Substitute.For(); +// effectiveBranchConfigurationFinderMock.GetConfigurations(branchMock, configuration).Returns(new[] { effectiveBranchConfiguration }); +// var incrementStrategyFinderMock = Substitute.For(); +// repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); +// var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); +// var preReleaseVersion = new BaseVersion( +// "prerelease", +// false, +// new SemanticVersion(1, 0, 1) +// { +// PreReleaseTag = new SemanticVersionPreReleaseTag +// { +// Name = "alpha", +// Number = 1 +// } +// }, +// GitToolsTestingExtensions.CreateMockCommit(), +// null +// ); +// var mainlineVersionCalculatorMock = Substitute.For(); +// mainlineVersionCalculatorMock.FindMainlineModeVersion(Arg.Any()).Returns(lowerVersion.SemanticVersion); +// var continuousDeploymentVersionCalculatorMock = Substitute.For(); + +// var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(preReleaseVersion, lowerVersion) }; +// var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, continuousDeploymentVersionCalculatorMock, +// repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); + +// // Act +// var nextVersion = unitUnderTest.FindVersion(); + +// // Assert +// nextVersion.BaseVersion.Source.ShouldNotBe(preReleaseVersion.Source); +// nextVersion.BaseVersion.SemanticVersion.ShouldNotBe(preReleaseVersion.SemanticVersion); +// nextVersion.BaseVersion.Source.ShouldBe(lowerVersion.Source); +// nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); +// } + +// private sealed class V1Strategy : IVersionStrategy +// { +// private readonly ICommit? when; + +// public V1Strategy(DateTimeOffset? when) +// { +// if (when != null) +// { +// this.when = GitToolsTestingExtensions.CreateMockCommit(); +// this.when.When.Returns(when.Value); +// } +// else +// { +// this.when = null; +// } +// } + +// public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) +// { +// yield return new BaseVersion("Source 1", false, new SemanticVersion(1), this.when, null); +// } +// } + +// private sealed class V2Strategy : IVersionStrategy +// { +// private readonly ICommit? when; + +// public V2Strategy(DateTimeOffset? when) +// { +// if (when != null) +// { +// this.when = GitToolsTestingExtensions.CreateMockCommit(); +// this.when.When.Returns(when.Value); +// } +// else +// { +// this.when = null; +// } +// } + +// public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) +// { +// yield return new BaseVersion("Source 2", true, new SemanticVersion(2), this.when, null); +// } +// } + +// private sealed class TestVersionStrategy : IVersionStrategy +// { +// private readonly IEnumerable baseVersions; + +// public TestVersionStrategy(params BaseVersion[] baseVersions) => this.baseVersions = baseVersions; + +// public IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) => this.baseVersions; +// } +//} diff --git a/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs index 2020f36d26..a0cdef1d3d 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs @@ -137,7 +137,7 @@ private static SemanticVersion BuildSemVer(int major, int minor, int patch, stri SemanticVersionPreReleaseTag? preReleaseTag = null; if (preReleaseName != null) { - preReleaseTag = new SemanticVersionPreReleaseTag(preReleaseName, preReleaseVersion); + preReleaseTag = new SemanticVersionPreReleaseTag(preReleaseName, preReleaseVersion, true); } SemanticVersionBuildMetaData? buildMetaDate = null; @@ -154,8 +154,8 @@ private static SemanticVersion BuildSemVer(int major, int minor, int patch, stri return new SemanticVersion(major, minor, patch) { - PreReleaseTag = preReleaseTag ?? new(), - BuildMetaData = buildMetaDate ?? new() + PreReleaseTag = preReleaseTag ?? SemanticVersionPreReleaseTag.Empty, + BuildMetaData = buildMetaDate ?? SemanticVersionBuildMetaData.Empty }; } } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs index 2306d62f38..db282ca23d 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Logging; using GitVersion.OutputVariables; @@ -31,7 +32,7 @@ public void Setup() [Test] public void ProvidesVariablesInContinuousDeliveryModeForPreRelease() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, @@ -46,42 +47,43 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreRelease() } }; - var configuration = new TestEffectiveConfiguration(); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); - - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } [Test] public void ProvidesVariablesInContinuousDeploymentModeForPreRelease() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, Patch = 3, - PreReleaseTag = "unstable.4", - BuildMetaData = new SemanticVersionBuildMetaData("5.Branch.develop") + PreReleaseTag = new SemanticVersionPreReleaseTag("unstable", 8, true), + BuildMetaData = new SemanticVersionBuildMetaData("Branch.develop") { VersionSourceSha = "versionSourceSha", Sha = "commitSha", ShortSha = "commitShortSha", + CommitsSinceVersionSource = 5, CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") } }; - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); - - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } [Test] public void ProvidesVariablesInContinuousDeliveryModeForStable() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, @@ -95,41 +97,43 @@ public void ProvidesVariablesInContinuousDeliveryModeForStable() } }; - var configuration = new TestEffectiveConfiguration(); + var configuration = GitFlowConfigurationBuilder.New.WithLabelPreReleaseWeight(0).Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); - - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } [Test] public void ProvidesVariablesInContinuousDeploymentModeForStable() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, Patch = 3, - BuildMetaData = new SemanticVersionBuildMetaData("5.Branch.develop") + PreReleaseTag = new SemanticVersionPreReleaseTag("ci", 5, true), + BuildMetaData = new SemanticVersionBuildMetaData("Branch.develop") { VersionSourceSha = "versionSourceSha", Sha = "commitSha", ShortSha = "commitShortSha", + CommitsSinceVersionSource = 5, CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") } }; - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, label: "ci"); - - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } [Test] public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, @@ -145,9 +149,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi } }; - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment); - - var variables = this.variableProvider.GetVariablesFor(semVer, configuration, SemanticVersion.Empty); + var configuration = GitFlowConfigurationBuilder.New.WithLabelPreReleaseWeight(0).Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, SemanticVersion.Empty); variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -155,13 +159,13 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi [Test] public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, Patch = 3, - PreReleaseTag = "PullRequest", - BuildMetaData = new SemanticVersionBuildMetaData("5.Branch.develop") + PreReleaseTag = new SemanticVersionPreReleaseTag("PullRequest2", 5, true), + BuildMetaData = new SemanticVersionBuildMetaData("Branch.develop") { Branch = "pull/2/merge", Sha = "commitSha", @@ -170,21 +174,23 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() } }; - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, labelNumberPattern: @"[/-](?\d+)[-/]"); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("pull-request")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - vars.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); + variables.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); } [Test] public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, Patch = 3, - BuildMetaData = new SemanticVersionBuildMetaData("5.Branch.develop") + PreReleaseTag = new SemanticVersionPreReleaseTag("feature", 5, true), + BuildMetaData = new SemanticVersionBuildMetaData("Branch.develop") { Branch = "feature", Sha = "commitSha", @@ -193,16 +199,17 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName } }; - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, label: "useBranchName"); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - vars.FullSemVer.ShouldBe("1.2.3-feature.5"); + variables.FullSemVer.ShouldBe("1.2.3-feature.5"); } [Test] public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, @@ -217,17 +224,17 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch() } }; - var configuration = new TestEffectiveConfiguration(); + var configuration = GitFlowConfigurationBuilder.New.WithLabelPreReleaseWeight(0).Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); - - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); } [Test] public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInfoFormat() { - var semVer = new SemanticVersion + var semanticVersion = new SemanticVersion { Major = 1, Minor = 2, @@ -242,12 +249,38 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomA } }; - var configuration = new TestEffectiveConfiguration( - assemblyInformationalFormat: "{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}" - ); + var configuration = GitFlowConfigurationBuilder.New.WithLabelPreReleaseWeight(0) + .WithAssemblyInformationalFormat("{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}") + .Build().GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + + variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + } + + [Test] + public void ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLabel() + { + var semanticVersion = new SemanticVersion + { + Major = 1, + Minor = 2, + Patch = 3, + PreReleaseTag = new(string.Empty, 9, true), + BuildMetaData = new("Branch.main") + { + Branch = "main", + VersionSourceSha = "versionSourceSha", + Sha = "commitSha", + ShortSha = "commitShortSha", + CommitsSinceVersionSource = 5, + CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") + } + }; - var vars = this.variableProvider.GetVariablesFor(semVer, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build() + .GetEffectiveConfiguration(ReferenceName.FromBranchName("main")); + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); - vars.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved")); + variables.ToJsonString().ShouldMatchApproved(_ => _.SubFolder("Approved")); } } diff --git a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs index c176e3b19c..1a9deb60b8 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs @@ -8,7 +8,7 @@ public static class ConfigurationExtensions public static EffectiveConfiguration GetEffectiveConfiguration(this IGitVersionConfiguration configuration, IBranch branch) => GetEffectiveConfiguration(configuration, branch.NotNull().Name); - private static EffectiveConfiguration GetEffectiveConfiguration(this IGitVersionConfiguration configuration, ReferenceName branchName) + public static EffectiveConfiguration GetEffectiveConfiguration(this IGitVersionConfiguration configuration, ReferenceName branchName) { IBranchConfiguration branchConfiguration = configuration.GetBranchConfiguration(branchName); return new EffectiveConfiguration(configuration, branchConfiguration); @@ -73,9 +73,10 @@ public static bool IsReleaseBranch(this IGitVersionConfiguration configuration, label = ConfigurationConstants.BranchNamePlaceholder; } + var value = branchNameOverride ?? branchName; + if (label?.Contains(ConfigurationConstants.BranchNamePlaceholder) == true) { - var value = branchNameOverride ?? branchName; if (!configuration.BranchPrefixToTrim.IsNullOrWhiteSpace()) { var branchNameTrimmed = value?.RegexReplace( @@ -89,6 +90,17 @@ public static bool IsReleaseBranch(this IGitVersionConfiguration configuration, label = label.Replace(ConfigurationConstants.BranchNamePlaceholder, value); } + // Evaluate tag number pattern and append to prerelease tag, preserving build metadata + if (!configuration.LabelNumberPattern.IsNullOrEmpty() && !value.IsNullOrEmpty() && label is not null) + { + var match = Regex.Match(value, configuration.LabelNumberPattern); + var numberGroup = match.Groups["number"]; + if (numberGroup.Success) + { + label += numberGroup.Value; + } + } + return label; } diff --git a/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs index 5d332dcc32..620f79c14d 100644 --- a/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs @@ -23,7 +23,7 @@ private GitFlowConfigurationBuilder() VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, LabelPreReleaseWeight = 60000, UpdateBuildNumber = true, - VersioningMode = VersioningMode.ContinuousDelivery, + VersioningMode = VersioningMode.ContinuousDeployment, RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit, @@ -40,7 +40,6 @@ private GitFlowConfigurationBuilder() { Increment = IncrementStrategy.Minor, RegularExpression = DevelopBranch.RegexPattern, - VersioningMode = VersioningMode.ContinuousDeployment, SourceBranches = new HashSet(), Label = "alpha", PreventIncrementOfMergedBranchVersion = false, @@ -72,6 +71,7 @@ private GitFlowConfigurationBuilder() { Increment = IncrementStrategy.None, RegularExpression = ReleaseBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { DevelopBranch.Name, MainBranch.Name, @@ -108,7 +108,7 @@ private GitFlowConfigurationBuilder() { Increment = IncrementStrategy.Inherit, RegularExpression = PullRequestBranch.RegexPattern, - VersioningMode = VersioningMode.ContinuousDelivery, + VersioningMode = VersioningMode.ContinuousDeployment, SourceBranches = new HashSet { DevelopBranch.Name, MainBranch.Name, diff --git a/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs index fbcc27b90a..65c426f350 100644 --- a/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs @@ -23,7 +23,7 @@ private GitHubFlowConfigurationBuilder() VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, LabelPreReleaseWeight = 60000, UpdateBuildNumber = true, - VersioningMode = VersioningMode.ContinuousDelivery, + VersioningMode = VersioningMode.ContinuousDeployment, RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit, @@ -56,6 +56,7 @@ private GitHubFlowConfigurationBuilder() { Increment = IncrementStrategy.None, RegularExpression = ReleaseBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { MainBranch.Name, ReleaseBranch.Name @@ -87,7 +88,7 @@ private GitHubFlowConfigurationBuilder() { Increment = IncrementStrategy.Inherit, RegularExpression = PullRequestBranch.RegexPattern, - VersioningMode = VersioningMode.ContinuousDelivery, + VersioningMode = VersioningMode.ContinuousDeployment, SourceBranches = new HashSet { MainBranch.Name, ReleaseBranch.Name, diff --git a/src/GitVersion.Core/Extensions/StringExtensions.cs b/src/GitVersion.Core/Extensions/StringExtensions.cs index 95b41e8349..e4a14a7b9c 100644 --- a/src/GitVersion.Core/Extensions/StringExtensions.cs +++ b/src/GitVersion.Core/Extensions/StringExtensions.cs @@ -104,4 +104,8 @@ public static bool IsEquivalentTo(this string self, string? other) => public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value) => string.IsNullOrWhiteSpace(value); public static bool IsEmpty([NotNullWhen(false)] this string? value) => string.Empty.Equals(value); + + public static string WithPrefixIfNotNullOrEmpty(this string value, string prefix) + => string.IsNullOrEmpty(value) ? value : prefix + value; + } diff --git a/src/GitVersion.Core/Git/SemanticVersion.cs b/src/GitVersion.Core/Git/SemanticVersion.cs index a68dd49faf..fecec1a77a 100644 --- a/src/GitVersion.Core/Git/SemanticVersion.cs +++ b/src/GitVersion.Core/Git/SemanticVersion.cs @@ -38,8 +38,8 @@ public SemanticVersion(long major = 0, long minor = 0, long patch = 0) this.Major = major; this.Minor = minor; this.Patch = patch; - this.PreReleaseTag = new SemanticVersionPreReleaseTag(); - this.BuildMetaData = new SemanticVersionBuildMetaData(); + this.PreReleaseTag = SemanticVersionPreReleaseTag.Empty; + this.BuildMetaData = SemanticVersionBuildMetaData.Empty; } public SemanticVersion(SemanticVersion semanticVersion) @@ -50,8 +50,8 @@ public SemanticVersion(SemanticVersion semanticVersion) this.Minor = semanticVersion.Minor; this.Patch = semanticVersion.Patch; - this.PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag); - this.BuildMetaData = new SemanticVersionBuildMetaData(semanticVersion.BuildMetaData); + this.PreReleaseTag = semanticVersion.PreReleaseTag; + this.BuildMetaData = semanticVersion.BuildMetaData; } public bool Equals(SemanticVersion? obj) @@ -310,13 +310,19 @@ public string ToString(string? format, IFormatProvider? formatProvider) } } + public SemanticVersion IncrementVersion(VersionField incrementStrategy) + => IncrementVersion(incrementStrategy, null, isMainRelease: true); + public SemanticVersion IncrementVersion(VersionField incrementStrategy, string? label) + => IncrementVersion(incrementStrategy, label, isMainRelease: false); + + private SemanticVersion IncrementVersion(VersionField incrementStrategy, string? label, bool isMainRelease) { var major = Major; var minor = Minor; var patch = Patch; - if (!PreReleaseTag.HasTag()) + if (isMainRelease || !PreReleaseTag.HasTag()) { switch (incrementStrategy) { @@ -339,26 +345,29 @@ public SemanticVersion IncrementVersion(VersionField incrementStrategy, string? } } - var preReleaseTagName = PreReleaseTag.Name; - var preReleaseTagNumber = PreReleaseTag.Number; + string preReleaseTagName = string.Empty; + long? preReleaseTagNumber = null; - if (PreReleaseTag.HasTag()) - { - preReleaseTagNumber++; - } - else if (!label.IsNullOrEmpty()) + if (!isMainRelease) { - preReleaseTagNumber = 1; - preReleaseTagName = label; + if (PreReleaseTag.HasTag()) + { + preReleaseTagNumber = PreReleaseTag.Number + 1; + preReleaseTagName = PreReleaseTag.Name; + } + else + { + preReleaseTagNumber = 1; + preReleaseTagName = label ?? string.Empty; + } } - return new() + return new SemanticVersion(this) { Major = major, Minor = minor, Patch = patch, - PreReleaseTag = new(preReleaseTagName, preReleaseTagNumber), - BuildMetaData = new(BuildMetaData) + PreReleaseTag = new SemanticVersionPreReleaseTag(preReleaseTagName, preReleaseTagNumber, true) }; } } diff --git a/src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs b/src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs index 85ca1bf4ff..734a0e2436 100644 --- a/src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs +++ b/src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs @@ -30,7 +30,7 @@ public class SemanticVersionBuildMetaData : IFormattable, IEquatable Name = string.Empty; - public SemanticVersionPreReleaseTag(string name, long? number) + public SemanticVersionPreReleaseTag(string name, long? number, bool promoteTagEvenIfNameIsEmpty) { Name = name.NotNull(); Number = number; + PromoteTagEvenIfNameIsEmpty = promoteTagEvenIfNameIsEmpty; } public SemanticVersionPreReleaseTag(SemanticVersionPreReleaseTag preReleaseTag) @@ -37,7 +38,7 @@ public SemanticVersionPreReleaseTag(SemanticVersionPreReleaseTag preReleaseTag) Name = preReleaseTag.Name; Number = preReleaseTag.Number; - PromotedFromCommits = preReleaseTag.PromotedFromCommits; + PromoteTagEvenIfNameIsEmpty = preReleaseTag.PromoteTagEvenIfNameIsEmpty; } public override bool Equals(object? obj) => Equals(obj as SemanticVersionPreReleaseTag); @@ -70,24 +71,21 @@ public SemanticVersionPreReleaseTag(SemanticVersionPreReleaseTag preReleaseTag) public static SemanticVersionPreReleaseTag Parse(string? preReleaseTag) { - if (preReleaseTag.IsNullOrEmpty()) - { - return new SemanticVersionPreReleaseTag(); - } + if (preReleaseTag.IsNullOrEmpty()) return Empty; var match = ParseRegex.Match(preReleaseTag); if (!match.Success) { // TODO check how to log this Console.WriteLine($"Unable to successfully parse semver tag {preReleaseTag}"); - return new SemanticVersionPreReleaseTag(); + return Empty; } var value = match.Groups["name"].Value; var number = match.Groups["number"].Success ? long.Parse(match.Groups["number"].Value) : (long?)null; return value.EndsWith("-") - ? new SemanticVersionPreReleaseTag(preReleaseTag, null) - : new SemanticVersionPreReleaseTag(value, number); + ? new SemanticVersionPreReleaseTag(preReleaseTag, null, true) + : new SemanticVersionPreReleaseTag(value, number, true); } public int CompareTo(SemanticVersionPreReleaseTag? other) @@ -130,6 +128,5 @@ public string ToString(string? format, IFormatProvider? formatProvider) }; } - public bool HasTag() => - !Name.IsNullOrEmpty() || (Number.HasValue && PromotedFromCommits != true); + public bool HasTag() => !Name.IsNullOrEmpty() || Number.HasValue && PromoteTagEvenIfNameIsEmpty; } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 1286de50e6..6d25e24a7d 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -585,6 +585,7 @@ GitVersion.SemanticVersion.BuildMetaData.init -> void GitVersion.SemanticVersion.CompareTo(GitVersion.SemanticVersion? value) -> int GitVersion.SemanticVersion.CompareTo(GitVersion.SemanticVersion? value, bool includePrerelease) -> int GitVersion.SemanticVersion.Equals(GitVersion.SemanticVersion? obj) -> bool +GitVersion.SemanticVersion.IncrementVersion(GitVersion.VersionField incrementStrategy) -> GitVersion.SemanticVersion! GitVersion.SemanticVersion.IncrementVersion(GitVersion.VersionField incrementStrategy, string? label) -> GitVersion.SemanticVersion! GitVersion.SemanticVersion.IsEmpty() -> bool GitVersion.SemanticVersion.IsLabeledWith(string! value) -> bool @@ -608,14 +609,14 @@ GitVersion.SemanticVersionBuildMetaData.CommitDate.get -> System.DateTimeOffset? GitVersion.SemanticVersionBuildMetaData.CommitDate.init -> void GitVersion.SemanticVersionBuildMetaData.CommitsSinceTag.get -> long? GitVersion.SemanticVersionBuildMetaData.CommitsSinceTag.init -> void -GitVersion.SemanticVersionBuildMetaData.CommitsSinceVersionSource.get -> long? +GitVersion.SemanticVersionBuildMetaData.CommitsSinceVersionSource.get -> long GitVersion.SemanticVersionBuildMetaData.CommitsSinceVersionSource.init -> void GitVersion.SemanticVersionBuildMetaData.Equals(GitVersion.SemanticVersionBuildMetaData? other) -> bool GitVersion.SemanticVersionBuildMetaData.OtherMetaData.get -> string? GitVersion.SemanticVersionBuildMetaData.OtherMetaData.init -> void GitVersion.SemanticVersionBuildMetaData.SemanticVersionBuildMetaData() -> void GitVersion.SemanticVersionBuildMetaData.SemanticVersionBuildMetaData(GitVersion.SemanticVersionBuildMetaData! buildMetaData) -> void -GitVersion.SemanticVersionBuildMetaData.SemanticVersionBuildMetaData(string? versionSourceSha, int? commitsSinceTag, string? branch, string? commitSha, string? commitShortSha, System.DateTimeOffset? commitDate, int numberOfUnCommittedChanges, string? otherMetadata = null) -> void +GitVersion.SemanticVersionBuildMetaData.SemanticVersionBuildMetaData(string? versionSourceSha, long? commitsSinceTag, string? branch, string? commitSha, string? commitShortSha, System.DateTimeOffset? commitDate, long numberOfUnCommittedChanges, string? otherMetadata = null) -> void GitVersion.SemanticVersionBuildMetaData.Sha.get -> string? GitVersion.SemanticVersionBuildMetaData.Sha.init -> void GitVersion.SemanticVersionBuildMetaData.ShortSha.get -> string? @@ -633,9 +634,9 @@ GitVersion.SemanticVersionFormatValues GitVersion.SemanticVersionFormatValues.AssemblyFileSemVer.get -> string? GitVersion.SemanticVersionFormatValues.AssemblySemVer.get -> string? GitVersion.SemanticVersionFormatValues.BranchName.get -> string? -GitVersion.SemanticVersionFormatValues.BuildMetaData.get -> string? +GitVersion.SemanticVersionFormatValues.BuildMetaData.get -> string! GitVersion.SemanticVersionFormatValues.CommitDate.get -> string? -GitVersion.SemanticVersionFormatValues.CommitsSinceVersionSource.get -> string? +GitVersion.SemanticVersionFormatValues.CommitsSinceVersionSource.get -> string! GitVersion.SemanticVersionFormatValues.EscapedBranchName.get -> string? GitVersion.SemanticVersionFormatValues.FullBuildMetaData.get -> string! GitVersion.SemanticVersionFormatValues.FullSemVer.get -> string! @@ -644,13 +645,13 @@ GitVersion.SemanticVersionFormatValues.Major.get -> string! GitVersion.SemanticVersionFormatValues.MajorMinorPatch.get -> string! GitVersion.SemanticVersionFormatValues.Minor.get -> string! GitVersion.SemanticVersionFormatValues.Patch.get -> string! -GitVersion.SemanticVersionFormatValues.PreReleaseLabel.get -> string? -GitVersion.SemanticVersionFormatValues.PreReleaseLabelWithDash.get -> string? -GitVersion.SemanticVersionFormatValues.PreReleaseNumber.get -> string? -GitVersion.SemanticVersionFormatValues.PreReleaseTag.get -> string? -GitVersion.SemanticVersionFormatValues.PreReleaseTagWithDash.get -> string? -GitVersion.SemanticVersionFormatValues.SemVer.get -> string! +GitVersion.SemanticVersionFormatValues.PreReleaseLabel.get -> string! +GitVersion.SemanticVersionFormatValues.PreReleaseLabelWithDash.get -> string! +GitVersion.SemanticVersionFormatValues.PreReleaseNumber.get -> string! +GitVersion.SemanticVersionFormatValues.PreReleaseTag.get -> string! +GitVersion.SemanticVersionFormatValues.PreReleaseTagWithDash.get -> string! GitVersion.SemanticVersionFormatValues.SemanticVersionFormatValues(GitVersion.SemanticVersion! semver, GitVersion.Configuration.EffectiveConfiguration! configuration) -> void +GitVersion.SemanticVersionFormatValues.SemVer.get -> string! GitVersion.SemanticVersionFormatValues.Sha.get -> string? GitVersion.SemanticVersionFormatValues.ShortSha.get -> string? GitVersion.SemanticVersionFormatValues.UncommittedChanges.get -> string! @@ -664,11 +665,11 @@ GitVersion.SemanticVersionPreReleaseTag.Name.get -> string! GitVersion.SemanticVersionPreReleaseTag.Name.init -> void GitVersion.SemanticVersionPreReleaseTag.Number.get -> long? GitVersion.SemanticVersionPreReleaseTag.Number.init -> void -GitVersion.SemanticVersionPreReleaseTag.PromotedFromCommits.get -> bool? -GitVersion.SemanticVersionPreReleaseTag.PromotedFromCommits.init -> void +GitVersion.SemanticVersionPreReleaseTag.PromoteTagEvenIfNameIsEmpty.get -> bool +GitVersion.SemanticVersionPreReleaseTag.PromoteTagEvenIfNameIsEmpty.init -> void GitVersion.SemanticVersionPreReleaseTag.SemanticVersionPreReleaseTag() -> void GitVersion.SemanticVersionPreReleaseTag.SemanticVersionPreReleaseTag(GitVersion.SemanticVersionPreReleaseTag! preReleaseTag) -> void -GitVersion.SemanticVersionPreReleaseTag.SemanticVersionPreReleaseTag(string! name, long? number) -> void +GitVersion.SemanticVersionPreReleaseTag.SemanticVersionPreReleaseTag(string! name, long? number, bool promoteTagEvenIfNameIsEmpty) -> void GitVersion.SemanticVersionPreReleaseTag.ToString(string! format) -> string! GitVersion.SemanticVersionPreReleaseTag.ToString(string? format, System.IFormatProvider? formatProvider) -> string! GitVersion.SemanticVersionWithTag @@ -714,6 +715,10 @@ GitVersion.VersionCalculation.CommitMessageIncrementMode GitVersion.VersionCalculation.CommitMessageIncrementMode.Disabled = 1 -> GitVersion.VersionCalculation.CommitMessageIncrementMode GitVersion.VersionCalculation.CommitMessageIncrementMode.Enabled = 0 -> GitVersion.VersionCalculation.CommitMessageIncrementMode GitVersion.VersionCalculation.CommitMessageIncrementMode.MergeMessageOnly = 2 -> GitVersion.VersionCalculation.CommitMessageIncrementMode +GitVersion.VersionCalculation.IContinuousDeliveryVersionCalculator +GitVersion.VersionCalculation.IContinuousDeliveryVersionCalculator.Calculate(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! +GitVersion.VersionCalculation.IContinuousDeploymentVersionCalculator +GitVersion.VersionCalculation.IContinuousDeploymentVersionCalculator.Calculate(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.IIncrementStrategyFinder @@ -722,8 +727,12 @@ GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(st GitVersion.VersionCalculation.IMainlineVersionCalculator GitVersion.VersionCalculation.IMainlineVersionCalculator.CreateVersionBuildMetaData(GitVersion.ICommit? baseVersionSource) -> GitVersion.SemanticVersionBuildMetaData! GitVersion.VersionCalculation.IMainlineVersionCalculator.FindMainlineModeVersion(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! +GitVersion.VersionCalculation.IManualDeploymentVersionCalculator +GitVersion.VersionCalculation.IManualDeploymentVersionCalculator.Calculate(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.INextVersionCalculator GitVersion.VersionCalculation.INextVersionCalculator.FindVersion() -> GitVersion.VersionCalculation.NextVersion! +GitVersion.VersionCalculation.ITrunkBasedVersionCalculator +GitVersion.VersionCalculation.ITrunkBasedVersionCalculator.Calculate(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.IVariableProvider GitVersion.VersionCalculation.IVariableProvider.GetVariablesFor(GitVersion.SemanticVersion! semanticVersion, GitVersion.Configuration.EffectiveConfiguration! configuration, GitVersion.SemanticVersion? currentCommitTaggedVersion) -> GitVersion.OutputVariables.GitVersionVariables! GitVersion.VersionCalculation.IVersionFilter @@ -810,6 +819,7 @@ static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(t static GitVersion.Configuration.ConfigurationExtensions.GetBranchSpecificLabel(this GitVersion.Configuration.EffectiveConfiguration! configuration, GitVersion.ReferenceName! branchName, string? branchNameOverride) -> string? static GitVersion.Configuration.ConfigurationExtensions.GetBranchSpecificLabel(this GitVersion.Configuration.EffectiveConfiguration! configuration, string? branchName, string? branchNameOverride) -> string? static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> GitVersion.Configuration.EffectiveConfiguration! +static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.ReferenceName! branchName) -> GitVersion.Configuration.EffectiveConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetFallbackBranchConfiguration(this GitVersion.Configuration.IGitVersionConfiguration! configuration) -> GitVersion.Configuration.IBranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetReleaseBranchConfiguration(this GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.List>! static GitVersion.Configuration.ConfigurationExtensions.IsReleaseBranch(this GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> bool @@ -843,6 +853,7 @@ static GitVersion.Extensions.StringExtensions.IsSwitchArgument(this string? valu static GitVersion.Extensions.StringExtensions.IsTrue(this string? value) -> bool static GitVersion.Extensions.StringExtensions.IsValidPath(this string? path) -> bool static GitVersion.Extensions.StringExtensions.RegexReplace(this string! input, string! pattern, string! replace, System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.None) -> string! +static GitVersion.Extensions.StringExtensions.WithPrefixIfNotNullOrEmpty(this string! value, string! prefix) -> string! static GitVersion.Helpers.EncodingHelper.DetectEncoding(System.Collections.Generic.IList! bytes) -> System.Text.Encoding? static GitVersion.Helpers.EncodingHelper.DetectEncoding(string? filename) -> System.Text.Encoding? static GitVersion.Helpers.PathHelper.Combine(string? path1) -> string! diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeliveryVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeliveryVersionCalculator.cs new file mode 100644 index 0000000000..3d4d2971f1 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeliveryVersionCalculator.cs @@ -0,0 +1,6 @@ +namespace GitVersion.VersionCalculation; + +public interface IContinuousDeliveryVersionCalculator +{ + SemanticVersion Calculate(NextVersion nextVersion); +} diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeploymentVersionCalculator.cs new file mode 100644 index 0000000000..9b13badf60 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IContinuousDeploymentVersionCalculator.cs @@ -0,0 +1,6 @@ +namespace GitVersion.VersionCalculation; + +public interface IContinuousDeploymentVersionCalculator +{ + SemanticVersion Calculate(NextVersion nextVersion); +} diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IManualDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IManualDeploymentVersionCalculator.cs new file mode 100644 index 0000000000..e1d5f64c3d --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IManualDeploymentVersionCalculator.cs @@ -0,0 +1,6 @@ +namespace GitVersion.VersionCalculation; + +public interface IManualDeploymentVersionCalculator +{ + SemanticVersion Calculate(NextVersion nextVersion); +} diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/ITrunkBasedVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/ITrunkBasedVersionCalculator.cs new file mode 100644 index 0000000000..23fe48184c --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/ITrunkBasedVersionCalculator.cs @@ -0,0 +1,6 @@ +namespace GitVersion.VersionCalculation; + +public interface ITrunkBasedVersionCalculator +{ + SemanticVersion Calculate(NextVersion nextVersion); +} diff --git a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs index d777e22f46..87dca264cf 100644 --- a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs @@ -17,7 +17,7 @@ public TaggedCommitVersionStrategy(IRepositoryStore repositoryStore, Lazy this.repositoryStore = repositoryStore.NotNull(); public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) - => GetSemanticVersions(configuration).Select(element => CreateBaseVersion(configuration, element)); + => GetSemanticVersions(configuration).Select(CreateBaseVersion); private IEnumerable GetSemanticVersions(EffectiveBranchConfiguration configuration) { @@ -81,22 +81,11 @@ private IEnumerable GetSemanticVersions(EffectiveBranchC } } - private BaseVersion CreateBaseVersion(EffectiveBranchConfiguration configuration, SemanticVersionWithTag semanticVersion) + private static BaseVersion CreateBaseVersion(SemanticVersionWithTag semanticVersion) { var tagCommit = semanticVersion.Tag.Commit; - var shouldUpdateVersion = tagCommit.Sha != Context.CurrentCommit?.Sha; - - if (!shouldUpdateVersion && !configuration.Value.Label.IsNullOrEmpty() && !semanticVersion.Value.PreReleaseTag.HasTag()) - { - return new BaseVersion( - $"Git tag '{semanticVersion.Tag.Name.Friendly}'", true, semanticVersion.Value, tagCommit, null - ); - } - else - { - return new BaseVersion( - $"Git tag '{semanticVersion.Tag.Name.Friendly}'", shouldUpdateVersion, semanticVersion.Value, tagCommit, null - ); - } + return new BaseVersion( + $"Git tag '{semanticVersion.Tag.Name.Friendly}'", true, semanticVersion.Value, tagCommit, null + ); } } diff --git a/src/GitVersion.Core/VersionCalculation/ContinuousDeliveryVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/ContinuousDeliveryVersionCalculator.cs new file mode 100644 index 0000000000..e680eb3ad3 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/ContinuousDeliveryVersionCalculator.cs @@ -0,0 +1,59 @@ +using System.Diagnostics.Contracts; +using GitVersion.Common; +using GitVersion.Logging; + +namespace GitVersion.VersionCalculation; + +internal sealed class ContinuousDeliveryVersionCalculator : NonTrunkBasedVersionCalculatorBase, IContinuousDeliveryVersionCalculator +{ + public ContinuousDeliveryVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) + : base(log, repositoryStore, versionContext) + { + } + + public SemanticVersion Calculate(NextVersion nextVersion) + { + using (this.log.IndentLog("Using continuous delivery workflow to calculate the incremented version.")) + { + var preReleaseTag = nextVersion.IncrementedVersion.PreReleaseTag; + if (!preReleaseTag.HasTag() || !preReleaseTag.Number.HasValue) + { + throw new WarningException("Continuous delivery requires a pre-release tag."); + } + + return CalculateInternal(nextVersion); + } + } + + private SemanticVersion CalculateInternal(NextVersion nextVersion) + { + if (ShouldTakeIncrementedVersion(nextVersion)) + { + var semanticVersion = CalculateIncrementedVersion(nextVersion); + + Contract.Assume(semanticVersion.PreReleaseTag.Number.HasValue); + Contract.Assume(semanticVersion.BuildMetaData.CommitsSinceTag.HasValue); + + return new SemanticVersion(semanticVersion) + { + PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag) + { + Number = semanticVersion.PreReleaseTag.Number.Value + semanticVersion.BuildMetaData.CommitsSinceTag - 1 + }, + BuildMetaData = new SemanticVersionBuildMetaData(semanticVersion.BuildMetaData) + { + CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value, + CommitsSinceTag = null + } + }; + } + else + { + var baseVersionBuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource); + return new SemanticVersion(nextVersion.BaseVersion.SemanticVersion) + { + BuildMetaData = baseVersionBuildMetaData + }; + } + } +} diff --git a/src/GitVersion.Core/VersionCalculation/ContinuousDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/ContinuousDeploymentVersionCalculator.cs new file mode 100644 index 0000000000..efb1fe49fc --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/ContinuousDeploymentVersionCalculator.cs @@ -0,0 +1,67 @@ +using System.Diagnostics.Contracts; +using GitVersion.Common; +using GitVersion.Logging; + +namespace GitVersion.VersionCalculation; + +internal sealed class ContinuousDeploymentVersionCalculator : NonTrunkBasedVersionCalculatorBase, IContinuousDeploymentVersionCalculator +{ + public ContinuousDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) + : base(log, repositoryStore, versionContext) + { + } + + public SemanticVersion Calculate(NextVersion nextVersion) + { + using (this.log.IndentLog("Using continuous deployment workflow to calculate the incremented version.")) + { + if (nextVersion.Configuration.Label is not null) + { + throw new WarningException("Continuous deployment requires no pre-release tag."); + } + if (!nextVersion.Configuration.IsMainline) + { + throw new WarningException("Continuous deployment is only supported for mainline branches."); + } + + return CalculateInternal(nextVersion); + } + } + + private SemanticVersion CalculateInternal(NextVersion nextVersion) + { + if (ShouldTakeIncrementedVersion(nextVersion)) + { + var semanticVersion = CalculateIncrementedVersion(nextVersion); + + Contract.Assume(semanticVersion.PreReleaseTag.Number.HasValue); + Contract.Assume(semanticVersion.BuildMetaData.CommitsSinceTag.HasValue); + + return new SemanticVersion(semanticVersion) + { + PreReleaseTag = SemanticVersionPreReleaseTag.Empty, + BuildMetaData = new SemanticVersionBuildMetaData(semanticVersion.BuildMetaData) + { + CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value, + CommitsSinceTag = null + } + }; + } + else + { + var baseVersionBuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource); + + Contract.Assume(baseVersionBuildMetaData.CommitsSinceTag.HasValue); + + return new SemanticVersion(nextVersion.BaseVersion.SemanticVersion) + { + PreReleaseTag = SemanticVersionPreReleaseTag.Empty, + BuildMetaData = new SemanticVersionBuildMetaData(baseVersionBuildMetaData) + { + CommitsSinceVersionSource = baseVersionBuildMetaData.CommitsSinceTag.Value, + CommitsSinceTag = null + } + }; + } + } +} diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/IVersionStrategy.cs similarity index 100% rename from src/GitVersion.Core/VersionCalculation/Abstractions/IVersionStrategy.cs rename to src/GitVersion.Core/VersionCalculation/IVersionStrategy.cs diff --git a/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs index bc2eac83bb..cbce3a703f 100644 --- a/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs @@ -26,13 +26,17 @@ public SemanticVersion FindMainlineModeVersion(NextVersion nextVersion) var baseVersion = nextVersion.BaseVersion; if (baseVersion.SemanticVersion.PreReleaseTag.HasTag()) + //if (!nextVersion.Configuration.Label.IsNullOrEmpty()) { throw new NotSupportedException("Mainline development mode doesn't yet support pre-release tags on main"); } using (this.log.IndentLog("Using mainline development mode to calculate current version")) { - var mainlineVersion = baseVersion.SemanticVersion; + SemanticVersion mainlineVersion = new(baseVersion.SemanticVersion) + { + PreReleaseTag = SemanticVersionPreReleaseTag.Empty + }; // Forward merge / PR // * feature/foo @@ -78,12 +82,19 @@ public SemanticVersion FindMainlineModeVersion(NextVersion nextVersion) var branchIncrement = FindMessageIncrement(null, Context.CurrentCommit, mergeBase, mainlineCommitLog); this.log.Info($"Performing {branchIncrement} increment for current branch "); - mainlineVersion = mainlineVersion.IncrementVersion(branchIncrement, null); + mainlineVersion = mainlineVersion.IncrementVersion(branchIncrement); + } + + var preReleaseTag = SemanticVersionPreReleaseTag.Empty; + var preReleaseTagName = nextVersion.IncrementedVersion.PreReleaseTag.Name; + if (!string.IsNullOrEmpty(preReleaseTagName)) + { + preReleaseTag = new SemanticVersionPreReleaseTag(preReleaseTagName, 1, true); } return new SemanticVersion(mainlineVersion) { - PreReleaseTag = new SemanticVersionPreReleaseTag(nextVersion.IncrementedVersion.PreReleaseTag), + PreReleaseTag = preReleaseTag, BuildMetaData = baseVersionBuildMetaData }; } @@ -133,7 +144,7 @@ private SemanticVersion AggregateMergeCommitIncrement(ICommit commit, List directCommit noBumpMessage: Context.Configuration.NoBumpMessage, commits: new[] { directCommit } ) ?? FindDefaultIncrementForBranch(Context, mainline); - mainlineVersion = mainlineVersion.IncrementVersion(directCommitIncrement, null); + mainlineVersion = mainlineVersion.IncrementVersion(directCommitIncrement); this.log.Info($"Direct commit on main {directCommit} incremented base versions {directCommitIncrement}, now {mainlineVersion}"); } diff --git a/src/GitVersion.Core/VersionCalculation/ManualDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/ManualDeploymentVersionCalculator.cs new file mode 100644 index 0000000000..d160223d4b --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/ManualDeploymentVersionCalculator.cs @@ -0,0 +1,41 @@ +using GitVersion.Common; +using GitVersion.Logging; + +namespace GitVersion.VersionCalculation; + +internal sealed class ManualDeploymentVersionCalculator : NonTrunkBasedVersionCalculatorBase, IManualDeploymentVersionCalculator +{ + public ManualDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) + : base(log, repositoryStore, versionContext) + { + } + + public SemanticVersion Calculate(NextVersion nextVersion) + { + using (this.log.IndentLog("Using manual deployment workflow to calculate the incremented version.")) + { + var preReleaseTag = nextVersion.IncrementedVersion.PreReleaseTag; + if (!preReleaseTag.HasTag() || !preReleaseTag.Number.HasValue) + { + throw new WarningException("Manual deployment requires a pre-release tag."); + } + + return CalculateInternal(nextVersion); + } + } + + private SemanticVersion CalculateInternal(NextVersion nextVersion) + { + if (ShouldTakeIncrementedVersion(nextVersion)) + { + return CalculateIncrementedVersion(nextVersion); + } + else + { + return new SemanticVersion(nextVersion.BaseVersion.SemanticVersion) + { + BuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource) + }; + } + } +} diff --git a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs index 9f0298739b..6f259d3ce0 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs @@ -1,5 +1,5 @@ +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using GitVersion.Common; using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.Logging; @@ -10,7 +10,10 @@ internal class NextVersionCalculator : INextVersionCalculator { private readonly ILog log; private readonly IMainlineVersionCalculator mainlineVersionCalculator; - private readonly IRepositoryStore repositoryStore; + private readonly ITrunkBasedVersionCalculator trunkBasedVersionCalculator; + private readonly IContinuousDeploymentVersionCalculator continuousDeploymentVersionCalculator; + private readonly IContinuousDeliveryVersionCalculator continuousDeliveryVersionCalculator; + private readonly IManualDeploymentVersionCalculator manualDeploymentVersionCalculator; private readonly Lazy versionContext; private readonly IVersionStrategy[] versionStrategies; private readonly IEffectiveBranchConfigurationFinder effectiveBranchConfigurationFinder; @@ -19,18 +22,24 @@ internal class NextVersionCalculator : INextVersionCalculator private GitVersionContext Context => this.versionContext.Value; public NextVersionCalculator(ILog log, - IMainlineVersionCalculator mainlineVersionCalculator, - IRepositoryStore repositoryStore, Lazy versionContext, + IMainlineVersionCalculator mainlineVersionCalculator, + ITrunkBasedVersionCalculator trunkBasedVersionCalculator, + IContinuousDeploymentVersionCalculator continuousDeploymentVersionCalculator, + IContinuousDeliveryVersionCalculator continuousDeliveryVersionCalculator, + IManualDeploymentVersionCalculator manualDeploymentVersionCalculator, IEnumerable versionStrategies, IEffectiveBranchConfigurationFinder effectiveBranchConfigurationFinder, IIncrementStrategyFinder incrementStrategyFinder) { this.log = log.NotNull(); + this.versionContext = versionContext.NotNull(); this.mainlineVersionCalculator = mainlineVersionCalculator.NotNull(); - this.repositoryStore = repositoryStore.NotNull(); + this.trunkBasedVersionCalculator = trunkBasedVersionCalculator.NotNull(); + this.continuousDeploymentVersionCalculator = continuousDeploymentVersionCalculator.NotNull(); + this.continuousDeliveryVersionCalculator = continuousDeliveryVersionCalculator.NotNull(); + this.manualDeploymentVersionCalculator = manualDeploymentVersionCalculator.NotNull(); this.incrementStrategyFinder = incrementStrategyFinder.NotNull(); - this.versionContext = versionContext.NotNull(); this.versionStrategies = versionStrategies.NotNull().ToArray(); this.effectiveBranchConfigurationFinder = effectiveBranchConfigurationFinder.NotNull(); this.incrementStrategyFinder = incrementStrategyFinder.NotNull(); @@ -45,73 +54,19 @@ public virtual NextVersion FindVersion() } var nextVersion = Calculate(Context.CurrentBranch, Context.Configuration); - - SemanticVersion semanticVersion; - if (nextVersion.Configuration.VersioningMode == VersioningMode.Mainline) - { - semanticVersion = this.mainlineVersionCalculator.FindMainlineModeVersion(nextVersion); - } - else - { - semanticVersion = FindOtherModeVersion(nextVersion); - } - - return new(semanticVersion, nextVersion.BaseVersion, new(nextVersion.Branch, nextVersion.Configuration)); + var incrementedVersion = CalculateIncrementedVersion(nextVersion.Configuration.VersioningMode, nextVersion); + return new(incrementedVersion, nextVersion.BaseVersion, new(nextVersion.Branch, nextVersion.Configuration)); } - private SemanticVersion FindOtherModeVersion(NextVersion nextVersion) + private SemanticVersion CalculateIncrementedVersion(VersioningMode versioningMode, NextVersion nextVersion) => versioningMode switch { - //// - // TODO: Please do a refactoring and move the logic from IMainlineVersionCalculator::CreateVersionBuildMetaData to some where else (Reason: Separation of concern violation). - var baseVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData( - nextVersion.BaseVersion.BaseVersionSource - ); - // - - var label = nextVersion.Configuration.GetBranchSpecificLabel( - Context.CurrentBranch.Name, nextVersion.BaseVersion.BranchNameOverride - ); - - //// - // TODO: We need to decide whether or not to calculate the upcoming semantic version or the previous one because of tagging. Actually this should be part of the branch configuration system. - var takeIncrementedVersion = baseVersionBuildMetaData.Sha != nextVersion.BaseVersion.BaseVersionSource?.Sha - || Context.CurrentCommitTaggedVersion == null - || !Context.CurrentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label); - // - - if (takeIncrementedVersion) - { - //// - // TODO: We need to consider somehow the IGitVersionConfiguration::Ignore property here!! - var semanticVersionWithTag = this.repositoryStore.GetTaggedSemanticVersionsOnBranch( - nextVersion.Branch, Context.Configuration.LabelPrefix, Context.Configuration.SemanticVersionFormat - ).FirstOrDefault(element => Context.CurrentCommit is null || element.Tag.Commit.When <= Context.CurrentCommit.When); - // - - if (semanticVersionWithTag?.Value.CompareTo(nextVersion.IncrementedVersion, false) > 0) - { - return new SemanticVersion(semanticVersionWithTag.Value) - { - PreReleaseTag = new SemanticVersionPreReleaseTag(nextVersion.IncrementedVersion.PreReleaseTag), - BuildMetaData = baseVersionBuildMetaData - }; - } - else - { - return new SemanticVersion(nextVersion.IncrementedVersion) - { - BuildMetaData = baseVersionBuildMetaData - }; - } - } - else - { - return new SemanticVersion(nextVersion.BaseVersion.SemanticVersion) - { - BuildMetaData = baseVersionBuildMetaData - }; - } - } + VersioningMode.ContinuousDelivery => this.manualDeploymentVersionCalculator.Calculate(nextVersion), + VersioningMode.ContinuousDeployment => nextVersion.Configuration.IsMainline && nextVersion.Configuration.Label is null + ? this.continuousDeploymentVersionCalculator.Calculate(nextVersion) + : this.continuousDeliveryVersionCalculator.Calculate(nextVersion), + VersioningMode.Mainline => this.mainlineVersionCalculator.FindMainlineModeVersion(nextVersion), + _ => throw new InvalidEnumArgumentException(nameof(versioningMode), (int)versioningMode, typeof(VersioningMode)), + }; private NextVersion Calculate(IBranch branch, IGitVersionConfiguration configuration) { diff --git a/src/GitVersion.Core/VersionCalculation/NonTrunkBasedVersionCalculatorBase.cs b/src/GitVersion.Core/VersionCalculation/NonTrunkBasedVersionCalculatorBase.cs new file mode 100644 index 0000000000..c13931abe0 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/NonTrunkBasedVersionCalculatorBase.cs @@ -0,0 +1,93 @@ +using GitVersion.Common; +using GitVersion.Configuration; +using GitVersion.Extensions; +using GitVersion.Logging; + +namespace GitVersion.VersionCalculation; + +internal abstract class NonTrunkBasedVersionCalculatorBase +{ + protected readonly ILog log; + protected readonly IRepositoryStore repositoryStore; + private readonly Lazy versionContext; + + protected GitVersionContext Context => this.versionContext.Value; + + public NonTrunkBasedVersionCalculatorBase(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) + { + this.log = log.NotNull(); + this.repositoryStore = repositoryStore.NotNull(); + this.versionContext = versionContext.NotNull(); + } + + protected bool ShouldTakeIncrementedVersion(NextVersion nextVersion) + { + var label = nextVersion.Configuration.GetBranchSpecificLabel( + Context.CurrentBranch.Name, nextVersion.BaseVersion.BranchNameOverride + ); + + //// + // TODO: We need to decide whether or not to calculate the upcoming semantic version or the previous one because of tagging. Actually this should be part of the branch configuration system. + return Context.CurrentCommit?.Sha != nextVersion.BaseVersion.BaseVersionSource?.Sha + || Context.CurrentCommitTaggedVersion == null + || !Context.CurrentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label); + // + } + + protected SemanticVersion CalculateIncrementedVersion(NextVersion nextVersion) + { + //// + // TODO: We need to consider somehow the IGitVersionConfiguration::Ignore property here!! + var semanticVersionWithTag = this.repositoryStore.GetTaggedSemanticVersionsOnBranch( + nextVersion.Branch, Context.Configuration.LabelPrefix, Context.Configuration.SemanticVersionFormat + ).FirstOrDefault(element => Context.CurrentCommit is null || element.Tag.Commit.When <= Context.CurrentCommit.When); + // + + if (semanticVersionWithTag?.Value.CompareTo(nextVersion.IncrementedVersion, false) > 0) + { + return new SemanticVersion(semanticVersionWithTag.Value) + { + PreReleaseTag = new SemanticVersionPreReleaseTag(nextVersion.IncrementedVersion.PreReleaseTag), + BuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource) + }; + } + else + { + return new SemanticVersion(nextVersion.IncrementedVersion) + { + BuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource) + }; + } + } + + protected SemanticVersionBuildMetaData CreateVersionBuildMetaData(ICommit? baseVersionSource) + { + int commitsSinceTag = 0; + if (Context.CurrentCommit != null) + { + var commitLogs = this.repositoryStore.GetCommitLog(baseVersionSource, Context.CurrentCommit); + + var ignore = Context.Configuration.Ignore; + if (!ignore.IsEmpty) + { + var shasToIgnore = new HashSet(ignore.Shas); + commitLogs = commitLogs + .Where(c => ignore.Before is null || (c.When > ignore.Before && !shasToIgnore.Contains(c.Sha))); + } + commitsSinceTag = commitLogs.Count(); + + this.log.Info($"{commitsSinceTag} commits found between {baseVersionSource} and {Context.CurrentCommit}"); + } + + var shortSha = Context.CurrentCommit?.Id.ToString(7); + return new SemanticVersionBuildMetaData( + versionSourceSha: baseVersionSource?.Sha, + commitsSinceTag: commitsSinceTag, + branch: Context.CurrentBranch.Name.Friendly, + commitSha: Context.CurrentCommit?.Sha, + commitShortSha: shortSha, + commitDate: Context.CurrentCommit?.When, + numberOfUnCommittedChanges: Context.NumberOfUncommittedChanges + ); + } +} diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs index 324288fd5a..007997d925 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs @@ -21,19 +21,19 @@ public SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfiguratio public string Patch => this.semver.Patch.ToString(); - public string? PreReleaseTag => this.semver.PreReleaseTag; + public string PreReleaseTag => this.semver.PreReleaseTag.ToString(); - public string? PreReleaseTagWithDash => this.semver.PreReleaseTag.HasTag() ? "-" + this.semver.PreReleaseTag : null; + public string PreReleaseTagWithDash => this.PreReleaseTag.WithPrefixIfNotNullOrEmpty("-"); - public string? PreReleaseLabel => this.semver.PreReleaseTag.HasTag() ? this.semver.PreReleaseTag.Name : null; + public string PreReleaseLabel => this.semver.PreReleaseTag.Name; - public string? PreReleaseLabelWithDash => this.semver.PreReleaseTag.HasTag() ? "-" + this.semver.PreReleaseTag.Name : null; + public string PreReleaseLabelWithDash => this.PreReleaseLabel.WithPrefixIfNotNullOrEmpty("-"); - public string? PreReleaseNumber => this.semver.PreReleaseTag.HasTag() ? this.semver.PreReleaseTag.Number.ToString() : null; + public string PreReleaseNumber => this.semver.PreReleaseTag.Number?.ToString() ?? string.Empty; public string WeightedPreReleaseNumber => GetWeightedPreReleaseNumber(); - public string? BuildMetaData => this.semver.BuildMetaData; + public string BuildMetaData => this.semver.BuildMetaData.ToString(); public string FullBuildMetaData => this.semver.BuildMetaData.ToString("f"); @@ -61,7 +61,7 @@ public SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfiguratio public string? VersionSourceSha => this.semver.BuildMetaData.VersionSourceSha; - public string? CommitsSinceVersionSource => this.semver.BuildMetaData.CommitsSinceVersionSource?.ToString(CultureInfo.InvariantCulture); + public string CommitsSinceVersionSource => this.semver.BuildMetaData.CommitsSinceVersionSource.ToString(CultureInfo.InvariantCulture); public string UncommittedChanges => this.semver.BuildMetaData.UncommittedChanges.ToString(CultureInfo.InvariantCulture); diff --git a/src/GitVersion.Core/VersionCalculation/TrunkBasedVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/TrunkBasedVersionCalculator.cs new file mode 100644 index 0000000000..a53f8fe5d1 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/TrunkBasedVersionCalculator.cs @@ -0,0 +1,8 @@ +namespace GitVersion.VersionCalculation; + +internal sealed class TrunkBasedVersionCalculator : ITrunkBasedVersionCalculator +{ + // TODO: Please implement trunk based version here and remove MainlineVersionCalculator. + public SemanticVersion Calculate(NextVersion nextVersion) => + throw new NotImplementedException("Trunk based version calculation is not yet implemented. Use Mainline mode instead."); +} diff --git a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs index d710c5ef64..cb8d714fb7 100644 --- a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs @@ -1,4 +1,3 @@ -using System.Text.RegularExpressions; using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.Helpers; @@ -18,43 +17,35 @@ public GitVersionVariables GetVariablesFor( semanticVersion.NotNull(); configuration.NotNull(); - var preReleaseTagName = semanticVersion.PreReleaseTag.Name; - var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment; - - var label = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null); - var isCommitTagged = currentCommitTaggedVersion is not null && currentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label); - - // Continuous Deployment always requires a pre-release tag unless the commit is tagged - if (isContinuousDeploymentMode && !isCommitTagged && !semanticVersion.PreReleaseTag.HasTag() && preReleaseTagName.IsNullOrEmpty()) + if (configuration.VersioningMode == VersioningMode.Mainline) { - preReleaseTagName = label ?? string.Empty; - } + var preReleaseTagName = semanticVersion.PreReleaseTag.Name; + var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment; - // Evaluate tag number pattern and append to prerelease tag, preserving build metadata - var appendTagNumberPattern = !configuration.LabelNumberPattern.IsNullOrEmpty() && semanticVersion.PreReleaseTag.HasTag(); - if (appendTagNumberPattern && semanticVersion.BuildMetaData.Branch != null && configuration.LabelNumberPattern != null) - { - var match = Regex.Match(semanticVersion.BuildMetaData.Branch, configuration.LabelNumberPattern); - var numberGroup = match.Groups["number"]; - if (numberGroup.Success) + var label = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null); + var isCommitTagged = currentCommitTaggedVersion is not null && currentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label); + + // Continuous Deployment always requires a pre-release tag unless the commit is tagged + if (isContinuousDeploymentMode && !isCommitTagged && !semanticVersion.PreReleaseTag.HasTag() && preReleaseTagName.IsNullOrEmpty()) { - preReleaseTagName += numberGroup.Value; + preReleaseTagName = label ?? string.Empty; } - } - if ((!isCommitTagged && isContinuousDeploymentMode) || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline) - { - semanticVersion = PromoteNumberOfCommitsToTagNumber(semanticVersion, preReleaseTagName); - } - else - { - semanticVersion = new(semanticVersion) + var appendTagNumberPattern = !configuration.LabelNumberPattern.IsNullOrEmpty() && semanticVersion.PreReleaseTag.HasTag(); + if ((!isCommitTagged && isContinuousDeploymentMode) || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline || isContinuousDeploymentMode && configuration.IsMainline) + { + semanticVersion = PromoteNumberOfCommitsToTagNumber(semanticVersion, preReleaseTagName); + } + else { - PreReleaseTag = new(semanticVersion.PreReleaseTag) + semanticVersion = new(semanticVersion) { - Name = preReleaseTagName - } - }; + PreReleaseTag = new(semanticVersion.PreReleaseTag) + { + Name = preReleaseTagName + } + }; + } } if (semanticVersion.CompareTo(currentCommitTaggedVersion) == 0) @@ -109,7 +100,6 @@ public GitVersionVariables GetVariablesFor( private static SemanticVersion PromoteNumberOfCommitsToTagNumber(SemanticVersion semanticVersion, string preReleaseTagName) { var preReleaseTagNumber = semanticVersion.PreReleaseTag.Number; - var preReleaseTagPromotedFromCommits = semanticVersion.PreReleaseTag.PromotedFromCommits; long buildMetaDataCommitsSinceVersionSource; var buildMetaDataCommitsSinceTag = semanticVersion.BuildMetaData.CommitsSinceTag; @@ -129,7 +119,6 @@ private static SemanticVersion PromoteNumberOfCommitsToTagNumber(SemanticVersion else { preReleaseTagNumber = semanticVersion.BuildMetaData.CommitsSinceTag; - preReleaseTagPromotedFromCommits = true; } buildMetaDataCommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value; buildMetaDataCommitsSinceTag = null; // why is this set to null ? @@ -140,8 +129,7 @@ private static SemanticVersion PromoteNumberOfCommitsToTagNumber(SemanticVersion PreReleaseTag = new(semanticVersion.PreReleaseTag) { Name = preReleaseTagName, - Number = preReleaseTagNumber, - PromotedFromCommits = preReleaseTagPromotedFromCommits + Number = preReleaseTagNumber }, BuildMetaData = new(semanticVersion.BuildMetaData) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs index 20d803f68b..87b26f735f 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs @@ -11,6 +11,10 @@ public void RegisterTypes(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs b/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs index f8ea12343d..1445f052aa 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs @@ -26,7 +26,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFile() fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""2"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""4"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.2.4"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4-1"""); } [Test] @@ -45,7 +45,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileInBuildServer() fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""0"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""1"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.0.1"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1-1"""); } [Test] @@ -70,7 +70,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuild( fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""2"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""4"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.2.4"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4-1"""); } [Test] @@ -95,7 +95,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildI fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""0"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""1"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.0.1"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1-1"""); } [Test] @@ -114,7 +114,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenIntermediateOut fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""2"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""4"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.2.4"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4-1"""); } [Test] @@ -133,7 +133,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileInBuildServerWhenIn fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""0"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""1"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.0.1"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1-1"""); } [Test] @@ -159,7 +159,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildA fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""2"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""4"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.2.4"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.2.4-1"""); } [Test] @@ -185,7 +185,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildA fileContent.ShouldContain($@"{nameof(GitVersionVariables.Minor)} = ""0"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.Patch)} = ""1"""); fileContent.ShouldContain($@"{nameof(GitVersionVariables.MajorMinorPatch)} = ""1.0.1"""); - fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1+1"""); + fileContent.ShouldContain($@"{nameof(GitVersionVariables.FullSemVer)} = ""1.0.1-1"""); } private static void AddGenerateGitVersionInformationTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty, string intermediateOutputPath = "$(MSBuildProjectDirectory)") diff --git a/src/GitVersion.MsBuild.Tests/Tasks/GetVersionTaskTests.cs b/src/GitVersion.MsBuild.Tests/Tasks/GetVersionTaskTests.cs index 303e42e6e7..974e010f54 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/GetVersionTaskTests.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/GetVersionTaskTests.cs @@ -35,7 +35,7 @@ public void GetVersionTaskShouldReturnVersionOutputVariables() result.Task.Minor.ShouldBe("2"); result.Task.Patch.ShouldBe("4"); result.Task.MajorMinorPatch.ShouldBe("1.2.4"); - result.Task.FullSemVer.ShouldBe("1.2.4+1"); + result.Task.FullSemVer.ShouldBe("1.2.4-1"); } [Test] @@ -51,14 +51,14 @@ public void GetVersionTaskShouldReturnVersionOutputVariablesForBuildServer() result.Task.Minor.ShouldBe("0"); result.Task.Patch.ShouldBe("1"); result.Task.MajorMinorPatch.ShouldBe("1.0.1"); - result.Task.FullSemVer.ShouldBe("1.0.1+1"); + result.Task.FullSemVer.ShouldBe("1.0.1-1"); } [TestCase(nameof(GitVersionVariables.Major), "1")] [TestCase(nameof(GitVersionVariables.Minor), "2")] [TestCase(nameof(GitVersionVariables.Patch), "4")] [TestCase(nameof(GitVersionVariables.MajorMinorPatch), "1.2.4")] - [TestCase(nameof(GitVersionVariables.FullSemVer), "1.2.4+1")] + [TestCase(nameof(GitVersionVariables.FullSemVer), "1.2.4-1")] public void GetVersionTaskShouldReturnVersionOutputVariablesWhenRunWithMsBuild(string outputProperty, string version) { const string taskName = nameof(GetVersion); @@ -77,7 +77,7 @@ public void GetVersionTaskShouldReturnVersionOutputVariablesWhenRunWithMsBuild(s [TestCase(nameof(GitVersionVariables.Minor), "0")] [TestCase(nameof(GitVersionVariables.Patch), "1")] [TestCase(nameof(GitVersionVariables.MajorMinorPatch), "1.0.1")] - [TestCase(nameof(GitVersionVariables.FullSemVer), "1.0.1+1")] + [TestCase(nameof(GitVersionVariables.FullSemVer), "1.0.1-1")] public void GetVersionTaskShouldReturnVersionOutputVariablesWhenRunWithMsBuildInBuildServer(string outputProperty, string version) { const string taskName = nameof(GetVersion); diff --git a/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs b/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs index b6b285aded..df0632d1b9 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs @@ -39,7 +39,7 @@ public void WriteVersionInfoTaskShouldLogOutputVariablesToBuildOutputInAzurePipe result.Success.ShouldBe(true); result.Errors.ShouldBe(0); - result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1+1"); + result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1-1"); } [TestCase("2021-02-14.1")] @@ -55,11 +55,11 @@ public void WriteVersionInfoTaskShouldNotUpdateBuildNumberInAzurePipeline(string result.Log.ShouldNotContain("##vso[build.updatebuildnumber]"); } - [TestCase("2021-02-14.1-$(GITVERSION.FullSemVer)", "2021-02-14.1-1.0.1+1")] + [TestCase("2021-02-14.1-$(GITVERSION.FullSemVer)", "2021-02-14.1-1.0.1-1")] [TestCase("2021-02-14.1-$(GITVERSION.SemVer)", "2021-02-14.1-1.0.1")] [TestCase("2021-02-14.1-$(GITVERSION.minor)", "2021-02-14.1-0")] [TestCase("2021-02-14.1-$(GITVERSION_MAJOR)", "2021-02-14.1-1")] - [TestCase("2021-02-14.1", "1.0.1+1")] + [TestCase("2021-02-14.1", "1.0.1-1")] public void WriteVersionInfoTaskShouldUpdateBuildNumberInAzurePipeline(string buildNumber, string expected) { var task = new WriteVersionInfoToBuildLog(); @@ -111,7 +111,7 @@ public void WriteVersionInfoTaskShouldLogOutputVariablesToBuildOutputWhenRunWith result.MsBuild.OverallSuccess.ShouldBe(true); result.MsBuild.ShouldAllBe(x => x.Succeeded); result.Output.ShouldNotBeNullOrWhiteSpace(); - result.Output.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1+1"); + result.Output.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1-1"); } private static void AddWriteVersionInfoToBuildLogTask(ProjectCreator project, string targetToRun, string taskName) diff --git a/src/GitVersion.Output.Tests/Output/AssemblyFileVersionTests.cs b/src/GitVersion.Output.Tests/Output/AssemblyFileVersionTests.cs index 3733979225..72726e88ea 100644 --- a/src/GitVersion.Output.Tests/Output/AssemblyFileVersionTests.cs +++ b/src/GitVersion.Output.Tests/Output/AssemblyFileVersionTests.cs @@ -16,7 +16,7 @@ public void ValidateAssemblyFileVersionBuilder(AssemblyFileVersioningScheme asse { var semVer = new SemanticVersion(major, minor, patch) { - PreReleaseTag = new SemanticVersionPreReleaseTag("Test", tag) + PreReleaseTag = new SemanticVersionPreReleaseTag("Test", tag, true) }; var assemblyFileVersion = semVer.GetAssemblyFileVersion(assemblyFileVersioningScheme);