diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index f6c6e7a6f5..767b654275 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -53,6 +53,7 @@ * VersionInBranchName * TrunkBased * The initialization wizard has been removed. +* On the `develop`, `release` and `hotfix` branch the introduced branch related property `prevent-increment-when-current-commit-tagged` has been set to `false` to get the incremented instead of the tagged semantic version. ## v5.0.0 diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index f4f6bb5e3a..25762f6073 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -31,18 +31,28 @@ found that is generally what is needed when using GitFlow. To see the effective configuration (defaults and overrides), you can run `gitversion /showConfig`. -To create your config file just type `gitversion init` in your repo directory, -after [installing][installing]. A minimal `GitVersion.yml` configuration file will be -created. Modify this to suit your needs. ## Global configuration -The global configuration looks like this: +The following supported workflow configurations are available in GitVersion and can be referenced by the workflow property: +- GitFlow (GitFlow/v1) +- GitHubFlow (GitHubFlow/v1) +- TrunkBased (TrunkBased/v1) + +Example of using a `TrunkBased` workflow with a different `tag-prefix`: + +```yaml +workflow: TrunkBased/v1 +tag-prefix: '[abc]' +``` + +The built-in configuration for the `GitFlow` workflow (`workflow: GitFlow/v1`) looks like: ```yaml assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' +version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* major-version-bump-message: '\+semver:\s?(breaking|major)' minor-version-bump-message: '\+semver:\s?(feature|minor)' patch-version-bump-message: '\+semver:\s?(fix|patch)' @@ -52,16 +62,22 @@ commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true semantic-version-format: Strict -strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName] +strategies: +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName branches: develop: - mode: ContinuousDeployment label: alpha increment: Minor prevent-increment-of-merged-branch-version: false + prevent-increment-when-tagged: false track-merge-target: true regex: ^dev(elop)?(ment)?$ source-branches: [] + is-source-branch-for: [] tracks-release-branches: true is-release-branch: false is-main-branch: false @@ -75,14 +91,17 @@ branches: source-branches: - develop - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true pre-release-weight: 55000 release: + mode: ManualDeployment label: beta increment: None prevent-increment-of-merged-branch-version: true + prevent-increment-when-tagged: false track-merge-target: false regex: ^releases?[/-] source-branches: @@ -90,12 +109,13 @@ branches: - main - support - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false pre-release-weight: 30000 feature: - mode: ContinuousDelivery + mode: ManualDeployment label: '{BranchName}' increment: Inherit regex: ^features?[/-](?.+) @@ -106,6 +126,7 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 pull-request: mode: ContinuousDelivery @@ -120,17 +141,21 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 hotfix: - mode: ContinuousDelivery + mode: ManualDeployment label: beta increment: Inherit + prevent-increment-when-tagged: false regex: ^hotfix(es)?[/-] source-branches: - release - main - support - hotfix + is-source-branch-for: [] + is-release-branch: true pre-release-weight: 30000 support: label: '' @@ -140,15 +165,16 @@ branches: regex: ^support[/-] source-branches: - main + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true pre-release-weight: 55000 unknown: - mode: ContinuousDelivery + mode: ManualDeployment label: '{BranchName}' increment: Inherit - regex: (?.*) + regex: (?.+) source-branches: - main - develop @@ -157,12 +183,200 @@ branches: - pull-request - hotfix - support + is-source-branch-for: [] +ignore: + sha: [] +mode: ContinuousDelivery +label: '{BranchName}' +increment: Inherit +prevent-increment-of-merged-branch-version: false +prevent-increment-when-tagged: true +track-merge-target: false +track-merge-message: true +commit-message-incrementing: Enabled +regex: '' +source-branches: [] +is-source-branch-for: [] +tracks-release-branches: false +is-release-branch: false +is-main-branch: false +``` + +The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like: + +```yaml +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +tag-prefix: '[vV]?' +version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* +major-version-bump-message: '\+semver:\s?(breaking|major)' +minor-version-bump-message: '\+semver:\s?(feature|minor)' +patch-version-bump-message: '\+semver:\s?(fix|patch)' +no-bump-message: '\+semver:\s?(none|skip)' +tag-pre-release-weight: 60000 +commit-date-format: yyyy-MM-dd +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict +strategies: +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName +branches: + main: + label: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + regex: ^master$|^main$ + source-branches: + - release + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 + release: + mode: ManualDeployment + label: beta + increment: None + prevent-increment-of-merged-branch-version: true + prevent-increment-when-tagged: false + track-merge-target: false + regex: ^releases?[/-] + source-branches: + - main + - release + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: true + is-main-branch: false + pre-release-weight: 30000 + feature: + mode: ManualDeployment + label: '{BranchName}' + increment: Inherit + regex: ^features?[/-](?.+) + source-branches: + - main + - release + - feature + is-source-branch-for: [] + pre-release-weight: 30000 + pull-request: + mode: ContinuousDelivery + label: PullRequest + increment: Inherit + label-number-pattern: '[/-](?\d+)' + regex: ^(pull|pull\-requests|pr)[/-] + source-branches: + - main + - release + - feature + is-source-branch-for: [] + pre-release-weight: 30000 + unknown: + mode: ManualDeployment + label: '{BranchName}' + increment: Inherit + regex: (?.+) + source-branches: + - main + - release + - feature + - pull-request + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false +prevent-increment-when-tagged: true +track-merge-target: false +track-merge-message: true +commit-message-incrementing: Enabled +regex: '' +source-branches: [] +is-source-branch-for: [] +tracks-release-branches: false +is-release-branch: false +is-main-branch: false +``` + +The supported built-in configuration for the `TrunkBased` workflow (`workflow: TrunkBased/v1`) looks like: + +```yaml +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +tag-prefix: '[vV]?' +version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* +major-version-bump-message: '\+semver:\s?(breaking|major)' +minor-version-bump-message: '\+semver:\s?(feature|minor)' +patch-version-bump-message: '\+semver:\s?(fix|patch)' +no-bump-message: '\+semver:\s?(none|skip)' +tag-pre-release-weight: 60000 +commit-date-format: yyyy-MM-dd +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict +strategies: +- TrunkBased +- ConfiguredNextVersion +branches: + main: + mode: ContinuousDeployment + label: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + regex: ^master$|^main$ + source-branches: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 + feature: + increment: Minor + regex: ^features?[/-](?.+) + prevent-increment-when-tagged: false + source-branches: + - main + pre-release-weight: 30000 + hotfix: + increment: Patch + regex: ^hotfix(es)?[/-](?.+) + prevent-increment-when-tagged: false + source-branches: + - main + pre-release-weight: 30000 + pull-request: + mode: ManualDeployment + label: PullRequest + increment: Inherit + label-number-pattern: '[/-](?\d+)' + regex: ^(pull|pull\-requests|pr)[/-] + source-branches: + - main + pre-release-weight: 30000 + unknown: + mode: ManualDeployment + increment: Inherit + regex: (?.+) + source-branches: + - main + - release + - feature + - pull-request +ignore: + sha: [] +mode: ManualDeployment +label: '{BranchName}' +increment: Inherit +prevent-increment-of-merged-branch-version: false +prevent-increment-when-tagged: true track-merge-target: false track-merge-message: true commit-message-incrementing: Enabled @@ -176,7 +390,7 @@ The details of the available options are as follows: ### workflow -The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1 +The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1 or TrunkBased/v1. Defaults to GitFlow/v1 if not set. ### next-version @@ -244,7 +458,7 @@ The default value is `{InformationalVersion}`. ### mode Sets the `mode` of how GitVersion should create a new version. Read more at -[versioning modes][modes]. +[deployment modes][modes]. ### increment @@ -588,6 +802,10 @@ In a GitFlow-based repository, setting this option can have implications on the better version source proposed by the `MergeMessageBaseVersionStrategy`. For more details and an in-depth analysis, please see [the discussion][2506]. +### prevent-increment-when-current-commit-tagged + +This branch related property controls the behvior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true. + ### label-number-pattern Pull requests require us to extract the pre-release number out of the branch @@ -677,9 +895,9 @@ Example of invalid `Strict`, but valid `Loose` ### strategies Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined: -* ConfiguredNextVersion -* MergeMessage -* TaggedCommit -* TrackReleaseBranches -* VersionInBranchName -* TrunkBased \ No newline at end of file +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName +- TrunkBased diff --git a/schemas/6.0/GitVersion.configuration.json b/schemas/6.0/GitVersion.configuration.json index 273bdbb8bd..c0ccdb4e88 100644 --- a/schemas/6.0/GitVersion.configuration.json +++ b/schemas/6.0/GitVersion.configuration.json @@ -129,6 +129,9 @@ "prevent-increment-of-merged-branch-version": { "$ref": "#/$defs/nullableOfBoolean2" }, + "prevent-increment-when-current-commit-tagged": { + "$ref": "#/$defs/nullableOfBoolean3" + }, "regex": { "$ref": "#/$defs/string2" }, @@ -157,13 +160,13 @@ ] }, "track-merge-message": { - "$ref": "#/$defs/nullableOfBoolean3" + "$ref": "#/$defs/nullableOfBoolean4" }, "track-merge-target": { - "$ref": "#/$defs/nullableOfBoolean4" + "$ref": "#/$defs/nullableOfBoolean5" }, "tracks-release-branches": { - "$ref": "#/$defs/nullableOfBoolean5" + "$ref": "#/$defs/nullableOfBoolean6" }, "update-build-number": { "description": "Whether to update the build number in the project file. Defaults to true.", @@ -176,6 +179,22 @@ "default": "(?[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*", "type": "string" }, + "strategies": { + "description": "Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: 'ConfiguredNextVersion', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.", + "type": "array", + "items": { + "description": "Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: 'ConfiguredNextVersion', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.", + "enum": [ + "None", + "ConfiguredNextVersion", + "MergeMessage", + "TaggedCommit", + "TrackReleaseBranches", + "VersionInBranchName", + "TrunkBased" + ] + } + }, "workflow": { "description": "The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'", "type": "string" @@ -215,6 +234,9 @@ "prevent-increment-of-merged-branch-version": { "$ref": "#/$defs/nullableOfBoolean2" }, + "prevent-increment-when-current-commit-tagged": { + "$ref": "#/$defs/nullableOfBoolean3" + }, "regex": { "$ref": "#/$defs/string2" }, @@ -222,13 +244,13 @@ "$ref": "#/$defs/hashSetOfString1" }, "track-merge-message": { - "$ref": "#/$defs/nullableOfBoolean3" + "$ref": "#/$defs/nullableOfBoolean4" }, "track-merge-target": { - "$ref": "#/$defs/nullableOfBoolean4" + "$ref": "#/$defs/nullableOfBoolean5" }, "tracks-release-branches": { - "$ref": "#/$defs/nullableOfBoolean5" + "$ref": "#/$defs/nullableOfBoolean6" } } }, @@ -245,8 +267,7 @@ "enum": [ "ManualDeployment", "ContinuousDelivery", - "ContinuousDeployment", - "TrunkBased" + "ContinuousDeployment" ] }, "incrementStrategy": { @@ -305,6 +326,13 @@ "null" ] }, + "nullableOfBoolean3": { + "description": "This branch related property controls the behvior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.", + "type": [ + "boolean", + "null" + ] + }, "string2": { "format": "regex", "description": "The regular expression pattern to use to match this branch.", @@ -318,21 +346,21 @@ "type": "string" } }, - "nullableOfBoolean3": { + "nullableOfBoolean4": { "description": "This property is a branch related property and gives the user the possibility to control the behavior of whether the merge commit message will be interpreted as a next version or not.", "type": [ "boolean", "null" ] }, - "nullableOfBoolean4": { + "nullableOfBoolean5": { "description": "Strategy which will look for tagged merge commits directly off the current branch.", "type": [ "boolean", "null" ] }, - "nullableOfBoolean5": { + "nullableOfBoolean6": { "description": "Indicates this branch configuration represents develop in GitFlow.", "type": [ "boolean", diff --git a/src/.run/GitVersion.Schema.run.xml b/src/.run/GitVersion.Schema.run.xml new file mode 100644 index 0000000000..0ecc7bc03c --- /dev/null +++ b/src/.run/GitVersion.Schema.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj index 5b66e2ca51..0d2f6f3e71 100644 --- a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj +++ b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj @@ -18,7 +18,6 @@ - diff --git a/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs index 79418b60ee..3cae60d9ad 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.VersionCalculation; @@ -144,10 +145,9 @@ private void AssertVariablesAreWrittenToFile(string propertyFile, string ps1File BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "f28807e615e9f06aec8a33c87780374e0c1f6fb8", CommitDate = new DateTimeOffset(2022, 4, 6, 16, 10, 59, TimeSpan.FromHours(10)) } }; - var configuration = new TestEffectiveConfiguration(); var variableProvider = this.sp.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); this.buildServer.WithPropertyFile(propertyFile); this.buildServer.WithPowershellFile(ps1File); diff --git a/src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs index b88018935a..1e5c220baf 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Logging; using GitVersion.OutputVariables; @@ -36,9 +37,7 @@ public void BuildNumberIsFullSemVer() } }; - var configuration = new TestEffectiveConfiguration(); - - var variables = this.buildServer.GetVariablesFor(semanticVersion, configuration, null); + var variables = this.buildServer.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); var buildAgent = this.sp.GetRequiredService(); buildAgent.WriteIntegration(writes.Add, variables); diff --git a/src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs index e353210a8a..cdc5de2b10 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.VersionCalculation; @@ -81,11 +82,9 @@ private void AssertVariablesAreWrittenToFile(string file) } }; - var configuration = new TestEffectiveConfiguration(); - var variableProvider = this.sp.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); this.buildServer.WithPropertyFile(file); diff --git a/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs index 718239396e..aa1e2ec6b0 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.VersionCalculation; @@ -59,13 +60,16 @@ private void AssertVariablesAreWrittenToFile(string file) Minor = 2, Patch = 3, PreReleaseTag = "beta1", - BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") } + BuildMetaData = new SemanticVersionBuildMetaData("5") + { + Sha = "commitSha", + CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") + } }; - var configuration = new TestEffectiveConfiguration(); var variableProvider = this.sp.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); this.buildServer.WithPropertyFile(file); diff --git a/src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs index 68305d905a..12ab86d632 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.VersionCalculation; @@ -133,11 +134,9 @@ private void AssertVariablesAreWrittenToFile(string file) BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") } }; - var configuration = new TestEffectiveConfiguration(); - var variableProvider = this.sp.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); this.buildServer.WithPropertyFile(file); diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs index 07351e0978..74910315b9 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs @@ -9,15 +9,11 @@ public class ConfigurationExtensionsTests : TestBase [Test] public void GetReleaseBranchConfigReturnsAllReleaseBranches() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary - { - { "foo", new BranchConfiguration() }, - { "bar", new BranchConfiguration { IsReleaseBranch = true } }, - { "baz", new BranchConfiguration { IsReleaseBranch = true } } - } - }; + var configuration = EmptyConfigurationBuilder.New + .WithBranch("foo", _ => _.WithRegularExpression("foo")) + .WithBranch("bar", _ => _.WithRegularExpression("bar").WithIsReleaseBranch(true)) + .WithBranch("baz", _ => _.WithRegularExpression("baz").WithIsReleaseBranch(true)) + .Build(); var result = configuration.GetReleaseBranchConfiguration(); diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index 5ec390d2d5..5062bedad7 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -22,6 +22,7 @@ branches: label: alpha increment: Minor prevent-increment-of-merged-branch-version: false + prevent-increment-when-current-commit-tagged: false track-merge-target: true regex: ^dev(elop)?(ment)?$ source-branches: [] @@ -49,6 +50,7 @@ branches: label: beta increment: None prevent-increment-of-merged-branch-version: true + prevent-increment-when-current-commit-tagged: false track-merge-target: false regex: ^releases?[/-] source-branches: @@ -94,6 +96,7 @@ branches: mode: ManualDeployment label: beta increment: Inherit + prevent-increment-when-current-commit-tagged: false regex: ^hotfix(es)?[/-] source-branches: - release @@ -136,6 +139,7 @@ mode: ContinuousDelivery label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false +prevent-increment-when-current-commit-tagged: true track-merge-target: false track-merge-message: true commit-message-incrementing: Enabled diff --git a/src/GitVersion.Configuration/BranchConfiguration.cs b/src/GitVersion.Configuration/BranchConfiguration.cs index 972c1e43b7..5607788ec3 100644 --- a/src/GitVersion.Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Configuration/BranchConfiguration.cs @@ -22,6 +22,10 @@ internal record BranchConfiguration : IBranchConfiguration [JsonPropertyDescription("Prevent increment of merged branch version.")] public bool? PreventIncrementOfMergedBranchVersion { get; internal set; } + [JsonPropertyName("prevent-increment-when-current-commit-tagged")] + [JsonPropertyDescription("This branch related property controls the behvior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.")] + public bool? PreventIncrementWhenCurrentCommitTagged { get; internal set; } + [JsonPropertyName("label-number-pattern")] [JsonPropertyDescription($"The regular expression pattern to use to extract the number from the branch name. Defaults to '{ConfigurationConstants.DefaultLabelNumberPattern}'.")] [JsonPropertyDefault(ConfigurationConstants.DefaultLabelNumberPattern)] @@ -89,6 +93,8 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration) Label = Label ?? configuration.Label, PreventIncrementOfMergedBranchVersion = PreventIncrementOfMergedBranchVersion ?? configuration.PreventIncrementOfMergedBranchVersion, + PreventIncrementWhenCurrentCommitTagged = PreventIncrementWhenCurrentCommitTagged + ?? configuration.PreventIncrementWhenCurrentCommitTagged, LabelNumberPattern = LabelNumberPattern ?? configuration.LabelNumberPattern, TrackMergeTarget = TrackMergeTarget ?? configuration.TrackMergeTarget, TrackMergeMessage = TrackMergeMessage ?? configuration.TrackMergeMessage, diff --git a/src/GitVersion.Configuration/BranchConfigurationBuilder.cs b/src/GitVersion.Configuration/BranchConfigurationBuilder.cs index 1df170ed06..9cbd81aec0 100644 --- a/src/GitVersion.Configuration/BranchConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/BranchConfigurationBuilder.cs @@ -10,6 +10,7 @@ internal class BranchConfigurationBuilder private string? label; private IncrementStrategy increment; private bool? preventIncrementOfMergedBranchVersion; + private bool? preventIncrementWhenCurrentCommitTagged; private string? labelNumberPattern; private bool? trackMergeTarget; private bool? trackMergeMessage; @@ -50,6 +51,12 @@ public virtual BranchConfigurationBuilder WithPreventIncrementOfMergedBranchVers return this; } + public virtual BranchConfigurationBuilder WithPreventIncrementWhenCurrentCommitTagged(bool? value) + { + this.preventIncrementWhenCurrentCommitTagged = value; + return this; + } + public virtual BranchConfigurationBuilder WithLabelNumberPattern(string? value) { this.labelNumberPattern = value; @@ -134,6 +141,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration WithLabel(value.Label); WithIncrement(value.Increment); WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); + WithPreventIncrementWhenCurrentCommitTagged(value.PreventIncrementWhenCurrentCommitTagged); WithLabelNumberPattern(value.LabelNumberPattern); WithTrackMergeTarget(value.TrackMergeTarget); WithTrackMergeMessage(value.TrackMergeMessage); @@ -162,6 +170,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration IsReleaseBranch = isReleaseBranch, LabelNumberPattern = labelNumberPattern, PreventIncrementOfMergedBranchVersion = preventIncrementOfMergedBranchVersion, + PreventIncrementWhenCurrentCommitTagged = preventIncrementWhenCurrentCommitTagged, PreReleaseWeight = preReleaseWeight, SourceBranches = sourceBranches, IsSourceBranchFor = isSourceBranchFor diff --git a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs index 5f14b2a5f8..4af15945f3 100644 --- a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs @@ -32,6 +32,7 @@ internal abstract class ConfigurationBuilderBase : IConfi private string? label; private IncrementStrategy increment = IncrementStrategy.Inherit; private bool? preventIncrementOfMergedBranchVersion; + private bool? preventIncrementWhenCurrentCommitTagged; private string? labelNumberPattern; private bool? trackMergeTarget; private bool? trackMergeMessage; @@ -255,6 +256,12 @@ public virtual TConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(b return (TConfigurationBuilder)this; } + public virtual TConfigurationBuilder WithPreventIncrementWhenCurrentCommitTagged(bool? value) + { + this.preventIncrementWhenCurrentCommitTagged = value; + return (TConfigurationBuilder)this; + } + public virtual TConfigurationBuilder WithLabelNumberPattern(string? value) { this.labelNumberPattern = value; @@ -338,6 +345,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration WithLabel(value.Label); WithIncrement(value.Increment); WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); + WithPreventIncrementWhenCurrentCommitTagged(value.PreventIncrementWhenCurrentCommitTagged); WithLabelNumberPattern(value.LabelNumberPattern); WithTrackMergeTarget(value.TrackMergeTarget); WithTrackMergeMessage(value.TrackMergeMessage); @@ -404,6 +412,7 @@ public virtual IGitVersionConfiguration Build() IsReleaseBranch = this.isReleaseBranch, LabelNumberPattern = this.labelNumberPattern, PreventIncrementOfMergedBranchVersion = this.preventIncrementOfMergedBranchVersion, + PreventIncrementWhenCurrentCommitTagged = this.preventIncrementWhenCurrentCommitTagged, PreReleaseWeight = this.preReleaseWeight }; diff --git a/src/GitVersion.Configuration/ConfigurationFileLocator.cs b/src/GitVersion.Configuration/ConfigurationFileLocator.cs index 4421d46383..eda43e01a0 100644 --- a/src/GitVersion.Configuration/ConfigurationFileLocator.cs +++ b/src/GitVersion.Configuration/ConfigurationFileLocator.cs @@ -25,7 +25,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory) public IGitVersionConfiguration ReadConfiguration(string? configFilePath) { - if (configFilePath == null || !fileSystem.Exists(configFilePath)) return new GitVersionConfiguration(); + if (configFilePath == null || !fileSystem.Exists(configFilePath)) return GitHubFlowConfigurationBuilder.New.Build(); var readAllText = fileSystem.ReadAllText(configFilePath); return ConfigurationSerializer.Read(new StringReader(readAllText)); diff --git a/src/GitVersion.Configuration/ConfigurationSerializer.cs b/src/GitVersion.Configuration/ConfigurationSerializer.cs index 34b45c27d4..bec88eac52 100644 --- a/src/GitVersion.Configuration/ConfigurationSerializer.cs +++ b/src/GitVersion.Configuration/ConfigurationSerializer.cs @@ -23,7 +23,7 @@ internal static class ConfigurationSerializer public static IGitVersionConfiguration Read(TextReader reader) { var configuration = Deserializer.Deserialize(reader); - return configuration ?? new GitVersionConfiguration(); + return configuration ?? GitHubFlowConfigurationBuilder.New.Build(); } public static void Write(IGitVersionConfiguration configuration, TextWriter writer) diff --git a/src/GitVersion.Configuration/EmptyConfigurationBuilder.cs b/src/GitVersion.Configuration/EmptyConfigurationBuilder.cs index 3dd9b34290..0ecd655721 100644 --- a/src/GitVersion.Configuration/EmptyConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/EmptyConfigurationBuilder.cs @@ -1,3 +1,6 @@ +using GitVersion.Extensions; +using GitVersion.VersionCalculation; + namespace GitVersion.Configuration; internal sealed class EmptyConfigurationBuilder : ConfigurationBuilderBase @@ -6,5 +9,15 @@ internal sealed class EmptyConfigurationBuilder : ConfigurationBuilderBase IIgnoreConfiguration.Shas => Shas; + IReadOnlySet IIgnoreConfiguration.Shas => Shas; [JsonPropertyName("sha")] [JsonPropertyDescription("A sequence of SHAs to be excluded from the version calculations.")] diff --git a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml index c3a60438a3..5062bedad7 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml @@ -22,9 +22,11 @@ branches: label: alpha increment: Minor prevent-increment-of-merged-branch-version: false + prevent-increment-when-current-commit-tagged: false track-merge-target: true regex: ^dev(elop)?(ment)?$ source-branches: [] + is-source-branch-for: [] tracks-release-branches: true is-release-branch: false is-main-branch: false @@ -38,6 +40,7 @@ branches: source-branches: - develop - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -47,6 +50,7 @@ branches: label: beta increment: None prevent-increment-of-merged-branch-version: true + prevent-increment-when-current-commit-tagged: false track-merge-target: false regex: ^releases?[/-] source-branches: @@ -54,6 +58,7 @@ branches: - main - support - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false @@ -70,6 +75,7 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 pull-request: mode: ContinuousDelivery @@ -84,17 +90,20 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 hotfix: mode: ManualDeployment label: beta increment: Inherit + prevent-increment-when-current-commit-tagged: false regex: ^hotfix(es)?[/-] source-branches: - release - main - support - hotfix + is-source-branch-for: [] is-release-branch: true pre-release-weight: 30000 support: @@ -105,6 +114,7 @@ branches: regex: ^support[/-] source-branches: - main + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -122,16 +132,20 @@ branches: - pull-request - hotfix - support + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false +prevent-increment-when-current-commit-tagged: true track-merge-target: false track-merge-message: true commit-message-incrementing: Enabled regex: '' +source-branches: [] +is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: false diff --git a/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml index 588dc246c1..87aaa13cf3 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml @@ -26,6 +26,7 @@ branches: regex: ^master$|^main$ source-branches: - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -35,11 +36,13 @@ branches: label: beta increment: None prevent-increment-of-merged-branch-version: true + prevent-increment-when-current-commit-tagged: false track-merge-target: false regex: ^releases?[/-] source-branches: - main - release + is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false @@ -53,6 +56,7 @@ branches: - main - release - feature + is-source-branch-for: [] pre-release-weight: 30000 pull-request: mode: ContinuousDelivery @@ -64,6 +68,7 @@ branches: - main - release - feature + is-source-branch-for: [] pre-release-weight: 30000 unknown: mode: ManualDeployment @@ -75,16 +80,20 @@ branches: - release - feature - pull-request + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false +prevent-increment-when-current-commit-tagged: true track-merge-target: false track-merge-message: true commit-message-incrementing: Enabled regex: '' +source-branches: [] +is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: false diff --git a/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml index eec0ab5973..c204d02e76 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml @@ -30,12 +30,14 @@ branches: feature: increment: Minor regex: ^features?[/-](?.+) + prevent-increment-when-current-commit-tagged: false source-branches: - main pre-release-weight: 30000 hotfix: increment: Patch regex: ^hotfix(es)?[/-](?.+) + prevent-increment-when-current-commit-tagged: false source-branches: - main pre-release-weight: 30000 @@ -63,6 +65,7 @@ mode: ManualDeployment label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false +prevent-increment-when-current-commit-tagged: true track-merge-target: false track-merge-message: true commit-message-incrementing: Enabled diff --git a/src/GitVersion.Core.Tests/CommitDateTests.cs b/src/GitVersion.Core.Tests/CommitDateTests.cs index 687b48294c..2b0d94ebd6 100644 --- a/src/GitVersion.Core.Tests/CommitDateTests.cs +++ b/src/GitVersion.Core.Tests/CommitDateTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; namespace GitVersion.Core.Tests; @@ -25,8 +26,8 @@ public void CommitDateFormatTest(string format, string expectedOutcome) { BuildMetaData = semanticVersionBuildMetaData // assume time zone is UTC }; - var configuration = new TestEffectiveConfiguration(commitDateFormat: format); - var formatValues = new SemanticVersionFormatValues(semanticVersion, configuration); + var configuration = EmptyConfigurationBuilder.New.WithCommitDateFormat(format).Build(); + var formatValues = new SemanticVersionFormatValues(semanticVersion, configuration, 0); Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome)); } diff --git a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs index 3ad6bfdc54..6c80ddcc5c 100644 --- a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs +++ b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs @@ -90,10 +90,10 @@ public static GitVersionVariables GetVersion(this RepositoryFixtureBase fixture, var context = contextOptions.Value; - var nextVersion = nextVersionCalculator.FindVersion(); - return variableProvider.GetVariablesFor( - nextVersion.IncrementedVersion, nextVersion.Configuration, context.CurrentCommitTaggedVersion - ); + var semanticVersion = nextVersionCalculator.FindVersion(); + + var effectiveConfiguration = context.Configuration.GetEffectiveConfiguration(context.CurrentBranch.Name); + return variableProvider.GetVariablesFor(semanticVersion, context.Configuration, effectiveConfiguration.PreReleaseWeight); } catch (Exception) { diff --git a/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs b/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs deleted file mode 100644 index 119ce644d1..0000000000 --- a/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs +++ /dev/null @@ -1,64 +0,0 @@ -using GitVersion.Configuration; -using GitVersion.Extensions; -using GitVersion.VersionCalculation; - -namespace GitVersion.Core.Tests.Helpers; - -public record TestEffectiveConfiguration : EffectiveConfiguration -{ - public TestEffectiveConfiguration( - AssemblyVersioningScheme assemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, - AssemblyFileVersioningScheme assemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - string? assemblyVersioningFormat = null, - string? assemblyFileVersioningFormat = null, - string? assemblyInformationalFormat = null, - DeploymentMode versioningMode = DeploymentMode.ContinuousDelivery, - string tagPrefix = ConfigurationConstants.DefaultTagPrefix, - string label = "ci", - string? nextVersion = null, - string regularExpression = "", - bool preventIncrementOfMergedBranchVersion = false, - string? labelNumberPattern = null, - bool trackMergeTarget = false, - string? majorMessage = null, - string? minorMessage = null, - string? patchMessage = null, - string? noBumpMessage = null, - CommitMessageIncrementMode commitMessageMode = CommitMessageIncrementMode.Enabled, - IEnumerable? versionFilters = null, - bool tracksReleaseBranches = false, - bool isRelease = false, - bool isMainBranch = false, - string commitDateFormat = "yyyy-MM-dd", - bool updateBuildNumber = false) : - base(assemblyVersioningScheme, - assemblyFileVersioningScheme, - assemblyInformationalFormat, - assemblyVersioningFormat, - assemblyFileVersioningFormat, - versioningMode, - tagPrefix, - label, - nextVersion, - IncrementStrategy.Patch, - regularExpression, - preventIncrementOfMergedBranchVersion, - labelNumberPattern, - trackMergeTarget, - majorMessage, - minorMessage, - patchMessage, - noBumpMessage, - commitMessageMode, - versionFilters ?? [], - tracksReleaseBranches, - isRelease, - isMainBranch, - commitDateFormat, - updateBuildNumber, - SemanticVersionFormat.Strict, - 0, - 0) - { - } -} diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs index 0bda894402..c56550b3cc 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs @@ -46,7 +46,7 @@ public void WhenDevelopBranchedFromTaggedCommitOnMainVersionDoesNotChange() using var fixture = new EmptyRepositoryFixture(); fixture.MakeATaggedCommit("1.0.0"); fixture.BranchTo("develop"); - fixture.AssertFullSemver("1.0.0"); + fixture.AssertFullSemver("1.1.0-alpha.0"); } [Test] @@ -203,7 +203,7 @@ public void TagOnHotfixShouldNotAffectDevelop() fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.1+1"); fixture.Repository.ApplyTag("1.2.1-beta.1"); - fixture.AssertFullSemver("1.2.1-beta.1"); + fixture.AssertFullSemver("1.2.1-beta.2+0"); Commands.Checkout(fixture.Repository, "develop"); fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.3.0-alpha.2"); @@ -515,7 +515,7 @@ public void PreventDecrementationOfVersionsOnTheMainBranch() fixture.ApplyTag("1.0.0-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0-beta.1", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-beta.2+0", configurationBuilder.Build()); // continue with more work on develop that may or may not end up in the 1.0.0 release fixture.Checkout("develop"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs b/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs index df3ab8e848..9f1a2a895b 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs @@ -91,7 +91,7 @@ public void GitFlowHotfixBranch() // Apply beta.1 tag should be exact tag fixture.ApplyTag("1.2.1-beta.1"); - fixture.AssertFullSemver("1.2.1-beta.1"); + fixture.AssertFullSemver("1.2.1-beta.2+0"); fixture.Checkout(MainBranch); fixture.MergeNoFF("hotfix/1.2.1"); fixture.SequenceDiagram.Destroy("hotfix/1.2.1"); @@ -132,7 +132,7 @@ public void GitFlowMinorRelease() // Apply beta.1 tag should be exact tag fixture.ApplyTag("1.3.0-beta.1"); - fixture.AssertFullSemver("1.3.0-beta.1"); + fixture.AssertFullSemver("1.3.0-beta.2+0"); // Make a commit after a tag should bump up the beta fixture.MakeACommit(); @@ -187,7 +187,7 @@ public void GitFlowMajorRelease() // Apply beta.1 tag should be exact tag fixture.ApplyTag("2.0.0-beta.1"); - fixture.AssertFullSemver("2.0.0-beta.1"); + fixture.AssertFullSemver("2.0.0-beta.2+0"); // Make a commit after a tag should bump up the beta fixture.MakeACommit(); @@ -243,7 +243,7 @@ public void GitFlowSupportHotfixRelease() // Apply beta.1 tag should be exact tag fixture.ApplyTag("1.3.1-beta.1"); - fixture.AssertFullSemver("1.3.1-beta.1"); + fixture.AssertFullSemver("1.3.1-beta.2+0"); fixture.Checkout("support/1.x"); fixture.MergeNoFF("hotfix/1.3.1"); fixture.SequenceDiagram.Destroy("hotfix/1.3.1"); @@ -286,7 +286,7 @@ public void GitFlowSupportMinorRelease() // Apply beta.1 tag should be exact tag fixture.ApplyTag("1.4.0-beta.1"); - fixture.AssertFullSemver("1.4.0-beta.1"); + fixture.AssertFullSemver("1.4.0-beta.2+0"); fixture.Checkout("support/1.x"); fixture.MergeNoFF("release/1.4.0"); fixture.SequenceDiagram.Destroy("release/1.4.0"); @@ -376,7 +376,7 @@ public void GitHubFlowMajorRelease() // Apply beta.1 tag should be exact tag fixture.ApplyTag("2.0.0-beta.1"); - fixture.AssertFullSemver("2.0.0-beta.1"); + fixture.AssertFullSemver("2.0.0-beta.2+0"); // test that the CommitsSinceVersionSource should still return commit count var version = fixture.GetVersion(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index b66bcf0cab..cd3658f260 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -22,7 +22,7 @@ public void PatchLatestReleaseExample() fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.1+2"); fixture.Repository.ApplyTag("1.2.1-beta.1"); - fixture.AssertFullSemver("1.2.1-beta.1"); + fixture.AssertFullSemver("1.2.1-beta.2+0"); fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.2+1"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs index fbe290046c..fcc4da1a08 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs @@ -324,7 +324,7 @@ public void PreventDecrementationOfVersionsOnTheDevelopmentBranch() fixture.ApplyTag("1.0.0-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0-beta.1", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-beta.2+0", configurationBuilder.Build()); // continue with more work on develop that may or may not end up in the 1.0.0 release fixture.Checkout("develop"); @@ -355,7 +355,7 @@ public void PreventDecrementationOfVersionsOnTheDevelopmentBranch() fixture.ApplyTag("1.0.0-beta.2"); // ✅ succeeds as expected - fixture.AssertFullSemver("1.0.0-beta.2", configurationBuilder.Build()); + fixture.AssertFullSemver("1.0.0-beta.3+0", configurationBuilder.Build()); fixture.Checkout("develop"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs index a1c52e27be..306ae3def6 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs @@ -1,6 +1,7 @@ using System.Globalization; using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; +using GitVersion.Extensions; using GitVersion.Helpers; using GitVersion.VersionCalculation; using LibGit2Sharp; @@ -179,7 +180,7 @@ public void EnsurePreReleaseTagLabelWillBeConsideredIfCurrentBranchIsRelease() fixture.ApplyTag("2.0.0-beta.1"); // ✅ succeeds as expected - fixture.AssertFullSemver("2.0.0-beta.1", configuration); + fixture.AssertFullSemver("2.0.0-beta.2+0", configuration); fixture.MakeACommit(); @@ -1050,4 +1051,171 @@ public void EnsureThePreReleaseTagIsCorrectlyGeneratedWhenPreReleaseLabelIsEmpty fixture.AssertFullSemver("0.0.1-5", configuration); } + + [TestCase("0.0.1-alpha.2", true, "0.0.1-alpha.2")] + [TestCase("0.0.1-alpha.2", false, "0.0.1-alpha.3+0")] + [TestCase("0.0.1", true, "0.0.1")] + [TestCase("0.0.1", false, "0.1.0-alpha.1+0")] + [TestCase("0.0.1-beta.2", true, "0.1.0-alpha.1+1")] + [TestCase("0.0.1-beta.2", false, "0.1.0-alpha.1+1")] + [TestCase("0.1.0-beta.2", true, "0.1.0-alpha.1+1")] + [TestCase("0.1.0-beta.2", false, "0.1.0-alpha.1+1")] + [TestCase("0.2.0-beta.2", true, "0.2.0-alpha.1+1")] + [TestCase("0.2.0-beta.2", false, "0.2.0-alpha.1+1")] + public void EnsurePreventIncrementWhenCurrentCommitTaggedOnDevelopWithDeploymentModeManualDeployment( + string tag, bool preventIncrementWhenCurrentCommitTagged, string version) + { + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("develop", _ => _ + .WithDeploymentMode(DeploymentMode.ManualDeployment) + .WithPreventIncrementWhenCurrentCommitTagged(preventIncrementWhenCurrentCommitTagged) + ).Build(); + + using var fixture = new EmptyRepositoryFixture("main"); + fixture.MakeACommit("A"); + if (!tag.IsNullOrEmpty()) fixture.ApplyTag(tag); + fixture.BranchTo("develop"); + + fixture.AssertFullSemver(version, configuration); + } + + [TestCase("0.0.1-alpha.2", true, "0.0.1-alpha.2")] + [TestCase("0.0.1-alpha.2", false, "0.0.1-alpha.2")] + [TestCase("0.0.1", true, "0.0.1")] + [TestCase("0.0.1", false, "0.1.0-alpha.0")] + [TestCase("0.0.1-beta.2", true, "0.1.0-alpha.1")] + [TestCase("0.0.1-beta.2", false, "0.1.0-alpha.1")] + [TestCase("0.1.0-beta.2", true, "0.1.0-alpha.1")] + [TestCase("0.1.0-beta.2", false, "0.1.0-alpha.1")] + [TestCase("0.2.0-beta.2", true, "0.2.0-alpha.1")] + [TestCase("0.2.0-beta.2", false, "0.2.0-alpha.1")] + public void EnsurePreventIncrementWhenCurrentCommitTaggedOnDevelopWithDeploymentModeContinuousDelivery( + string tag, bool preventIncrementWhenCurrentCommitTagged, string version) + { + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("develop", _ => _ + .WithDeploymentMode(DeploymentMode.ContinuousDelivery) + .WithPreventIncrementWhenCurrentCommitTagged(preventIncrementWhenCurrentCommitTagged) + ).Build(); + + using var fixture = new EmptyRepositoryFixture("main"); + fixture.MakeACommit("A"); + if (!tag.IsNullOrEmpty()) fixture.ApplyTag(tag); + fixture.BranchTo("develop"); + + fixture.AssertFullSemver(version, configuration); + } + + [TestCase("0.0.1-alpha.2", true, "0.0.1")] + [TestCase("0.0.1-alpha.2", false, "0.0.1")] + [TestCase("0.0.1", true, "0.0.1")] + [TestCase("0.0.1", false, "0.1.0")] + [TestCase("0.0.1-beta.2", true, "0.1.0")] + [TestCase("0.0.1-beta.2", false, "0.1.0")] + [TestCase("0.1.0-beta.2", true, "0.1.0")] + [TestCase("0.1.0-beta.2", false, "0.1.0")] + [TestCase("0.2.0-beta.2", true, "0.2.0")] + [TestCase("0.2.0-beta.2", false, "0.2.0")] + public void EnsurePreventIncrementWhenCurrentCommitTaggedOnDevelopWithDeploymentModeContinuousDeployment( + string tag, bool preventIncrementWhenCurrentCommitTagged, string version) + { + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("develop", _ => _ + .WithDeploymentMode(DeploymentMode.ContinuousDeployment) + .WithPreventIncrementWhenCurrentCommitTagged(preventIncrementWhenCurrentCommitTagged) + ).Build(); + + using var fixture = new EmptyRepositoryFixture("main"); + fixture.MakeACommit("A"); + if (!tag.IsNullOrEmpty()) fixture.ApplyTag(tag); + fixture.BranchTo("develop"); + + fixture.AssertFullSemver(version, configuration); + } + + [TestCase(true, "1.0.0")] + [TestCase(false, "6.0.0-alpha.1+0")] + public void EnsurePreventIncrementWhenCurrentCommitTaggedOnDevelopWithNextVersion(bool preventIncrementWhenCurrentCommitTagged, string semVersion) + { + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("6.0.0") + .WithBranch("develop", _ => _ + .WithDeploymentMode(DeploymentMode.ManualDeployment) + .WithPreventIncrementWhenCurrentCommitTagged(preventIncrementWhenCurrentCommitTagged) + ).Build(); + + using var fixture = new EmptyRepositoryFixture(); + + fixture.MakeACommit(); + fixture.MakeATaggedCommit("1.0.0"); + fixture.BranchTo("develop"); + + fixture.AssertFullSemver(semVersion, configuration); + } + + [TestCase(null, true, "6.0.0-beta.1+0")] + [TestCase(null, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0" }, true, "5.0.0")] + [TestCase(new[] { "5.0.0" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "6.0.0" }, true, "6.0.0")] + [TestCase(new[] { "6.0.0" }, false, "6.1.0-beta.1+0")] + [TestCase(new[] { "7.0.0" }, true, "7.0.0")] + [TestCase(new[] { "7.0.0" }, false, "7.1.0-beta.1+0")] + [TestCase(new[] { "5.0.0-alpha.2" }, true, "6.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0-alpha.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "6.0.0-alpha.2" }, true, "6.0.0-beta.1+0")] + [TestCase(new[] { "6.0.0-alpha.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "7.0.0-alpha.2" }, true, "7.0.0-beta.1+0")] + [TestCase(new[] { "7.0.0-alpha.2" }, false, "7.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0-beta.2" }, true, "5.0.0-beta.2")] + [TestCase(new[] { "5.0.0-beta.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "6.0.0-beta.2" }, true, "6.0.0-beta.2")] + [TestCase(new[] { "6.0.0-beta.2" }, false, "6.0.0-beta.3+0")] + [TestCase(new[] { "7.0.0-beta.2" }, true, "7.0.0-beta.2")] + [TestCase(new[] { "7.0.0-beta.2" }, false, "7.0.0-beta.3+0")] + [TestCase(new[] { "5.0.0", "6.0.0" }, true, "6.0.0")] + [TestCase(new[] { "5.0.0", "6.0.0" }, false, "6.1.0-beta.1+0")] + [TestCase(new[] { "6.0.0", "5.0.0" }, true, "6.0.0")] + [TestCase(new[] { "6.0.0", "5.0.0" }, false, "6.1.0-beta.1+0")] + [TestCase(new[] { "6.0.0", "7.0.0" }, true, "7.0.0")] + [TestCase(new[] { "6.0.0", "7.0.0" }, false, "7.1.0-beta.1+0")] + [TestCase(new[] { "7.0.0", "6.0.0" }, true, "7.0.0")] + [TestCase(new[] { "7.0.0", "6.0.0" }, false, "7.1.0-beta.1+0")] + [TestCase(new[] { "4.0.0", "5.0.0-alpha.2" }, true, "4.0.0")] + [TestCase(new[] { "4.0.0", "5.0.0-alpha.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0-alpha.2", "4.0.0" }, true, "4.0.0")] + [TestCase(new[] { "5.0.0-alpha.2", "4.0.0" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "4.0.0", "5.0.0-beta.2" }, true, "5.0.0-beta.2")] + [TestCase(new[] { "4.0.0", "5.0.0-beta.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0-beta.2", "4.0.0" }, true, "5.0.0-beta.2")] + [TestCase(new[] { "5.0.0-beta.2", "4.0.0" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "4.0.0-alpha.2", "5.0.0-beta.2" }, true, "5.0.0-beta.2")] + [TestCase(new[] { "4.0.0-alpha.2", "5.0.0-beta.2" }, false, "6.0.0-beta.1+0")] + [TestCase(new[] { "5.0.0-beta.2", "4.0.0-alpha.2" }, true, "5.0.0-beta.2")] + [TestCase(new[] { "5.0.0-beta.2", "4.0.0-alpha.2" }, false, "6.0.0-beta.1+0")] + public void EnsurePreventIncrementWhenCurrentCommitTaggedOnReleaseBranchAndIncrementMinor( + string[]? tags, bool preventIncrementWhenCurrentCommitTagged, string semVersion) + { + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("release", _ => _ + .WithDeploymentMode(DeploymentMode.ManualDeployment) + .WithPreventIncrementWhenCurrentCommitTagged(preventIncrementWhenCurrentCommitTagged) + .WithIncrement(IncrementStrategy.Minor) + ).Build(); + + using var fixture = new EmptyRepositoryFixture(); + fixture.MakeACommit(); + + if (tags is not null) + { + foreach (string tag in tags) + { + fixture.ApplyTag(tag); + } + } + + fixture.BranchTo("release/6.0.0"); + + fixture.AssertFullSemver(semVersion, configuration); + } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs index b468e1e336..f8a9d103a2 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -90,7 +90,7 @@ public void CanTakePreReleaseVersionFromReleasesBranchWithNumericPreReleaseTag() fixture.Repository.ApplyTag("v2.0.0-beta.1"); var variables = fixture.GetVersion(); - Assert.That(variables.FullSemVer, Is.EqualTo("2.0.0-beta.1")); + Assert.That(variables.FullSemVer, Is.EqualTo("2.0.0-beta.2+0")); } [Test] diff --git a/src/GitVersion.Core.Tests/MergeMessageTests.cs b/src/GitVersion.Core.Tests/MergeMessageTests.cs index c200794ada..546355d2b6 100644 --- a/src/GitVersion.Core.Tests/MergeMessageTests.cs +++ b/src/GitVersion.Core.Tests/MergeMessageTests.cs @@ -35,10 +35,10 @@ public void EmptyTagPrefix(string? prefix) { // Arrange const string message = "Updated some code."; - var conf = new GitVersionConfiguration { TagPrefix = prefix }; + var configuration = GitHubFlowConfigurationBuilder.New.WithTagPrefix(prefix).Build(); // Act - var sut = new MergeMessage(message, conf); + var sut = new MergeMessage(message, configuration); // Assert sut.TargetBranch.ShouldBeNull(); diff --git a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreRelease.cs b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreRelease.cs index 245601d6c6..fe27b519c3 100644 --- a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreRelease.cs +++ b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreRelease.cs @@ -490,10 +490,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-foo.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-foo.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-foo.2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -516,10 +516,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-foo.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -542,10 +542,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-foo.2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -568,10 +568,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-foo.2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-foo.1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -719,10 +719,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar.2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-bar.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-bar.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-bar.2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -745,10 +745,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-bar.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-bar.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-bar.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-bar.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -771,10 +771,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-bar.2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-bar.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-bar.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-bar.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] @@ -797,10 +797,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-bar.2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-bar.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-bar.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-bar.1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "0.0.0-4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "0.0.0-4")] diff --git a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseBar.cs b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseBar.cs index f75c14ca09..7d6dbda2a5 100644 --- a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseBar.cs +++ b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseBar.cs @@ -261,10 +261,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.1-1+0")] @@ -287,10 +287,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.1-2+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.2-1+0")] @@ -313,10 +313,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.1.0-2+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.1.1-1+0")] @@ -339,10 +339,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "1.0.0-2+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "1.0.1-1+0")] @@ -490,10 +490,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-foo.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-foo.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-foo.2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.1-1+0")] @@ -516,10 +516,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-foo.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-foo.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.1-1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.2-1+0")] @@ -542,10 +542,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.2-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-foo.2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.1.0-1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.1.1-1+0")] @@ -568,10 +568,10 @@ public string GetVersionWithEmptyLabelOnMainAndTakeAlwaysIncrementedVersionOnFea [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "1.0.0-foo.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.2.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-foo.2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-foo.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-foo.1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-bar")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-bar")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-foo.1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "1.0.0-1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "1.0.1-1+0")] diff --git a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseFoo.cs b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseFoo.cs index 03e6ad2538..5eff04e7e5 100644 --- a/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseFoo.cs +++ b/src/GitVersion.Core.Tests/TrunkBased/TrunkBasedScenariosWithAGitHubFlow+GivenAMainBranchWithOneCommitBranchedToFeatureWhenCommitTaggedAsPreReleaseFoo.cs @@ -261,10 +261,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.1-1+0")] @@ -287,10 +287,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.1-2+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.2-1+0")] @@ -313,10 +313,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.1.0-2+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.1.1-1+0")] @@ -339,10 +339,10 @@ public string GetVersionWithNoLabelOnMainAndTakeAlwaysIncrementedVersionOnFeatur [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "1.0.0-2+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "1.0.1-1+0")] @@ -719,10 +719,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu return fixture!.GetVersion(trunkBased).FullSemVer; } - [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-bar.2+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.1-bar.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-bar.1+0")] - [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.None, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.0-bar.2+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.None, "", ExpectedResult = "0.0.0-1+0")] [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, "", ExpectedResult = "0.0.1-1+0")] @@ -745,10 +745,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.None, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.None, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.1-bar.2+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.2-bar.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.1.0-bar.1+0")] - [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, null, ExpectedResult = "0.0.2-bar.1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, "", ExpectedResult = "0.0.1-1+0")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, "", ExpectedResult = "0.0.2-1+0")] @@ -771,10 +771,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Patch, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.1.0-bar.2+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.1.1-bar.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.2.0-bar.1+0")] - [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "1.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, null, ExpectedResult = "0.2.0-bar.1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, "", ExpectedResult = "0.1.0-1+0")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, "", ExpectedResult = "0.1.1-1+0")] @@ -797,10 +797,10 @@ public string GetVersionWithLabelFooOnMainAndTakeAlwaysIncrementedVersionOnFeatu [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Minor, IncrementStrategy.Inherit, "{BranchName}", ExpectedResult = "0.0.0-foo.4")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "1.0.0-bar.2+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "1.0.1-bar.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "1.1.0-bar.1+0")] - [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "2.0.0-bar.1+0")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, null, ExpectedResult = "0.0.0-foo.4")] + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, null, ExpectedResult = "0.0.0-foo.4")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, null, ExpectedResult = "2.0.0-bar.1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.None, "", ExpectedResult = "1.0.0-1+0")] [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, "", ExpectedResult = "1.0.1-1+0")] diff --git a/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs index 3c851ca0f4..3db950eb62 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.VersionCalculation; using Microsoft.Extensions.DependencyInjection; @@ -22,12 +23,10 @@ public void Json() BuildMetaData = new("versionSourceSha", 5, "feature1", "commitSha", "commitShortSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"), 0) }; - var configuration = new TestEffectiveConfiguration(); - var serviceProvider = ConfigureServices(); var variableProvider = serviceProvider.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs index c1802459bc..aa9fe03aa4 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs @@ -46,9 +46,9 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreRelease() } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -72,9 +72,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForPreRelease() } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("unstable")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -96,9 +96,9 @@ public void ProvidesVariablesInContinuousDeliveryModeForStable() } }; - var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -122,9 +122,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStable() } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -148,9 +148,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi } }; - var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, SemanticVersion.Empty); + var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -173,9 +173,9 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("pull-request")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("pull-request")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); } @@ -198,9 +198,9 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToBranchName() } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.FullSemVer.ShouldBe("1.2.3-feature.5"); } @@ -223,9 +223,9 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch() } }; - var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0).Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -250,8 +250,9 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomA var configuration = GitFlowConfigurationBuilder.New.WithTagPreReleaseWeight(0) .WithAssemblyInformationalFormat("{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}") - .Build().GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + .Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("develop")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved")); } @@ -276,9 +277,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLab } }; - var configuration = GitFlowConfigurationBuilder.New.Build() - .GetEffectiveConfiguration(ReferenceName.FromBranchName("main")); - var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, null); + var configuration = GitFlowConfigurationBuilder.New.Build(); + int preReleaseWeight = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("main")).PreReleaseWeight; + var variables = this.variableProvider.GetVariablesFor(semanticVersion, configuration, preReleaseWeight); variables.ToJson().ShouldMatchApproved(_ => _.SubFolder("Approved")); } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/VersionSourceTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/VersionSourceTests.cs index 8dbd3fdcca..3bb50fbf16 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/VersionSourceTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/VersionSourceTests.cs @@ -20,10 +20,10 @@ public void VersionSourceSha() var nextVersionCalculator = GetNextVersionCalculator(fixture.Repository.ToGitRepository()); - var nextVersion = nextVersionCalculator.FindVersion(); + var semanticVersion = nextVersionCalculator.FindVersion(); - nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBeNull(); - nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(3); + semanticVersion.BuildMetaData.VersionSourceSha.ShouldBeNull(); + semanticVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(3); } [Test] @@ -35,10 +35,10 @@ public void VersionSourceShaOneCommit() var nextVersionCalculator = GetNextVersionCalculator(fixture.Repository.ToGitRepository()); - var nextVersion = nextVersionCalculator.FindVersion(); + var semanticVersion = nextVersionCalculator.FindVersion(); - nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBeNull(); - nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1); + semanticVersion.BuildMetaData.VersionSourceSha.ShouldBeNull(); + semanticVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1); } [Test] @@ -54,10 +54,10 @@ public void VersionSourceShaUsingTag() var nextVersionCalculator = GetNextVersionCalculator(fixture.Repository.ToGitRepository()); - var nextVersion = nextVersionCalculator.FindVersion(); + var semanticVersion = nextVersionCalculator.FindVersion(); - nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBe(secondCommitSha); - nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1); + semanticVersion.BuildMetaData.VersionSourceSha.ShouldBe(secondCommitSha); + semanticVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1); } private static INextVersionCalculator GetNextVersionCalculator(IGitRepository repository) diff --git a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index 6482eb5b16..0f2da66eb4 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -19,7 +19,7 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon branchConfiguration = branchConfiguration.Inherit(fallbackBranchConfiguration); if (!branchConfiguration.DeploymentMode.HasValue) - throw new("Configuration value for 'Versioning mode' has no value. (this should not happen, please report an issue)"); + throw new("Configuration value for 'Deployment mode' has no value. (this should not happen, please report an issue)"); if (!configuration.AssemblyVersioningScheme.HasValue) throw new("Configuration value for 'AssemblyVersioningScheme' has no value. (this should not happen, please report an issue)"); @@ -33,6 +33,9 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon if (!configuration.TagPreReleaseWeight.HasValue) throw new("Configuration value for 'TagPreReleaseWeight' has no value. (this should not happen, please report an issue)"); + if (configuration.CommitDateFormat.IsNullOrEmpty()) + throw new("Configuration value for 'CommitDateFormat' has no value. (this should not happen, please report an issue)"); + AssemblyVersioningScheme = configuration.AssemblyVersioningScheme.Value; AssemblyFileVersioningScheme = configuration.AssemblyFileVersioningScheme.Value; AssemblyInformationalFormat = configuration.AssemblyInformationalFormat; @@ -46,6 +49,7 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon Increment = branchConfiguration.Increment; RegularExpression = branchConfiguration.RegularExpression; PreventIncrementOfMergedBranchVersion = branchConfiguration.PreventIncrementOfMergedBranchVersion ?? false; + PreventIncrementWhenCurrentCommitTagged = branchConfiguration.PreventIncrementWhenCurrentCommitTagged ?? true; LabelNumberPattern = branchConfiguration.LabelNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget ?? false; TrackMergeMessage = branchConfiguration.TrackMergeMessage ?? true; @@ -66,65 +70,6 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon TagPreReleaseWeight = configuration.TagPreReleaseWeight.Value; } - protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningScheme, - AssemblyFileVersioningScheme assemblyFileVersioningScheme, - string? assemblyInformationalFormat, - string? assemblyVersioningFormat, - string? assemblyFileVersioningFormat, - DeploymentMode versioningMode, - string? tagPrefix, - string label, - string? nextVersion, - IncrementStrategy increment, - string? regularExpression, - bool preventIncrementOfMergedBranchVersion, - string? labelNumberPattern, - bool trackMergeTarget, - string? majorVersionBumpMessage, - string? minorVersionBumpMessage, - string? patchVersionBumpMessage, - string? noBumpMessage, - CommitMessageIncrementMode commitMessageIncrementing, - IEnumerable versionFilters, - bool tracksReleaseBranches, - bool isReleaseBranch, - bool isMainBranch, - string? commitDateFormat, - bool updateBuildNumber, - SemanticVersionFormat semanticVersionFormat, - int preReleaseWeight, - int tagPreReleaseWeight) - { - AssemblyVersioningScheme = assemblyVersioningScheme; - AssemblyFileVersioningScheme = assemblyFileVersioningScheme; - AssemblyInformationalFormat = assemblyInformationalFormat; - AssemblyVersioningFormat = assemblyVersioningFormat; - AssemblyFileVersioningFormat = assemblyFileVersioningFormat; - DeploymentMode = versioningMode; - TagPrefix = tagPrefix; - Label = label; - NextVersion = nextVersion; - Increment = increment; - RegularExpression = regularExpression; - PreventIncrementOfMergedBranchVersion = preventIncrementOfMergedBranchVersion; - LabelNumberPattern = labelNumberPattern; - TrackMergeTarget = trackMergeTarget; - MajorVersionBumpMessage = majorVersionBumpMessage; - MinorVersionBumpMessage = minorVersionBumpMessage; - PatchVersionBumpMessage = patchVersionBumpMessage; - NoBumpMessage = noBumpMessage; - CommitMessageIncrementing = commitMessageIncrementing; - VersionFilters = versionFilters; - TracksReleaseBranches = tracksReleaseBranches; - IsReleaseBranch = isReleaseBranch; - IsMainBranch = isMainBranch; - CommitDateFormat = commitDateFormat; - UpdateBuildNumber = updateBuildNumber; - SemanticVersionFormat = semanticVersionFormat; - PreReleaseWeight = preReleaseWeight; - TagPreReleaseWeight = tagPreReleaseWeight; - } - public bool TracksReleaseBranches { get; } public bool IsReleaseBranch { get; } public bool IsMainBranch { get; } @@ -155,6 +100,8 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche public bool PreventIncrementOfMergedBranchVersion { get; } + public bool PreventIncrementWhenCurrentCommitTagged { get; } + public string? LabelNumberPattern { get; } public bool TrackMergeTarget { get; } diff --git a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs index 1da6adfe70..2367aada08 100644 --- a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs @@ -13,6 +13,8 @@ public interface IBranchConfiguration bool? PreventIncrementOfMergedBranchVersion { get; } + bool? PreventIncrementWhenCurrentCommitTagged { get; } + string? LabelNumberPattern { get; } bool? TrackMergeTarget { get; } diff --git a/src/GitVersion.Core/Configuration/IIgnoreConfiguration.cs b/src/GitVersion.Core/Configuration/IIgnoreConfiguration.cs index 21a7dd5a97..21efe431d6 100644 --- a/src/GitVersion.Core/Configuration/IIgnoreConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IIgnoreConfiguration.cs @@ -1,11 +1,10 @@ -namespace GitVersion.Configuration +namespace GitVersion.Configuration; + +public interface IIgnoreConfiguration { - public interface IIgnoreConfiguration - { - DateTimeOffset? Before { get; } + DateTimeOffset? Before { get; } - IReadOnlyCollection Shas { get; } + IReadOnlySet Shas { get; } - public bool IsEmpty => Before == null && Shas.Count == 0; - } + public bool IsEmpty => Before == null && Shas.Count == 0; } diff --git a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs index ef813cef07..178309b953 100644 --- a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs +++ b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs @@ -34,12 +34,6 @@ public interface IRepositoryStore IEnumerable GetSourceBranches(IBranch branch, IGitVersionConfiguration configuration, IEnumerable excludedBranches); - SemanticVersion? GetCurrentCommitTaggedVersion(ICommit? commit, string? tagPrefix, SemanticVersionFormat format, bool handleDetachedBranch); - - IReadOnlyList GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format); - - IReadOnlyList GetTaggedSemanticVersionsOnBranch(IBranch branch, string? tagPrefix, SemanticVersionFormat format); - bool IsCommitOnBranch(ICommit? baseVersionSource, IBranch branch, ICommit firstMatchingCommit); int GetNumberOfUncommittedChanges(); diff --git a/src/GitVersion.Core/Core/BranchRepository.cs b/src/GitVersion.Core/Core/BranchRepository.cs index 6962fb1d7d..1e7223198a 100644 --- a/src/GitVersion.Core/Core/BranchRepository.cs +++ b/src/GitVersion.Core/Core/BranchRepository.cs @@ -3,21 +3,18 @@ namespace GitVersion.Core; -internal sealed class BranchRepository(Lazy versionContext, IGitRepository gitRepository) - : IBranchRepository +internal sealed class BranchRepository(IGitRepository gitRepository) : IBranchRepository { - private GitVersionContext VersionContext => this.versionContextLazy.Value; - private readonly Lazy versionContextLazy = versionContext.NotNull(); - private readonly IGitRepository gitRepository = gitRepository.NotNull(); - public IEnumerable GetMainBranches(params IBranch[] excludeBranches) - => GetBranches([.. excludeBranches], configuration => configuration.IsMainBranch == true); + public IEnumerable GetMainBranches(IGitVersionConfiguration configuration, params IBranch[] excludeBranches) + => GetBranches(configuration, [.. excludeBranches], configuration => configuration.IsMainBranch == true); - public IEnumerable GetReleaseBranches(params IBranch[] excludeBranches) - => GetBranches([.. excludeBranches], configuration => configuration.IsReleaseBranch == true); + public IEnumerable GetReleaseBranches(IGitVersionConfiguration configuration, params IBranch[] excludeBranches) + => GetBranches(configuration, [.. excludeBranches], configuration => configuration.IsReleaseBranch == true); - private IEnumerable GetBranches(HashSet excludeBranches, Func predicate) + private IEnumerable GetBranches( + IGitVersionConfiguration configuration, HashSet excludeBranches, Func predicate) { predicate.NotNull(); @@ -25,7 +22,7 @@ private IEnumerable GetBranches(HashSet excludeBranches, Func< { if (!excludeBranches.Contains(branch)) { - var branchConfiguration = VersionContext.Configuration.GetBranchConfiguration(branch.Name); + var branchConfiguration = configuration.GetBranchConfiguration(branch.Name); if (predicate(branchConfiguration)) { yield return branch; diff --git a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs index b0fa55dfbe..53331f05ae 100644 --- a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs +++ b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.Helpers; using GitVersion.Logging; @@ -19,7 +20,8 @@ internal class GitVersionCalculateTool : IGitVersionCalculateTool private readonly IOptions options; private readonly Lazy versionContext; - private GitVersionContext context => this.versionContext.Value; + + private GitVersionContext Context => this.versionContext.Value; public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IGitPreparer gitPreparer, @@ -50,10 +52,12 @@ public GitVersionVariables CalculateVersionVariables() if (versionVariables != null) return versionVariables; - var nextVersion = this.nextVersionCalculator.FindVersion(); + var semanticVersion = this.nextVersionCalculator.FindVersion(); + + var branchConfiguration = Context.Configuration.GetBranchConfiguration(Context.CurrentBranch); + EffectiveConfiguration effectiveConfiguration = new(Context.Configuration, branchConfiguration); versionVariables = this.variableProvider.GetVariablesFor( - nextVersion.IncrementedVersion, nextVersion.Configuration, context.CurrentCommitTaggedVersion - ); + semanticVersion, Context.Configuration, effectiveConfiguration.PreReleaseWeight); if (gitVersionOptions.Settings.NoCache) return versionVariables; try diff --git a/src/GitVersion.Core/Core/GitVersionContextFactory.cs b/src/GitVersion.Core/Core/GitVersionContextFactory.cs index 2f1537d7b5..2e16b5c903 100644 --- a/src/GitVersion.Core/Core/GitVersionContextFactory.cs +++ b/src/GitVersion.Core/Core/GitVersionContextFactory.cs @@ -1,5 +1,6 @@ using GitVersion.Common; using GitVersion.Configuration; +using GitVersion.Core; using GitVersion.Extensions; using Microsoft.Extensions.Options; @@ -9,18 +10,22 @@ internal class GitVersionContextFactory : IGitVersionContextFactory { private readonly IConfigurationProvider configurationProvider; private readonly IRepositoryStore repositoryStore; + private readonly ITaggedSemanticVersionRepository taggedSemanticVersionRepository; private readonly IOptions options; - public GitVersionContextFactory(IConfigurationProvider configurationProvider, IRepositoryStore repositoryStore, IOptions options) + public GitVersionContextFactory(IConfigurationProvider configurationProvider, IRepositoryStore repositoryStore, + ITaggedSemanticVersionRepository taggedSemanticVersionRepository, IOptions options) { this.configurationProvider = configurationProvider.NotNull(); this.repositoryStore = repositoryStore.NotNull(); + this.taggedSemanticVersionRepository = taggedSemanticVersionRepository.NotNull(); this.options = options.NotNull(); } public GitVersionContext Create(GitVersionOptions gitVersionOptions) { - var currentBranch = this.repositoryStore.GetTargetBranch(gitVersionOptions.RepositoryInfo.TargetBranch) ?? throw new InvalidOperationException("Need a branch to operate on"); + var currentBranch = this.repositoryStore.GetTargetBranch(gitVersionOptions.RepositoryInfo.TargetBranch) + ?? throw new InvalidOperationException("Need a branch to operate on"); var currentCommit = this.repositoryStore.GetCurrentCommit(currentBranch, gitVersionOptions.RepositoryInfo.CommitId); if (currentCommit is null) throw new GitVersionException("No commits found on the current branch."); @@ -33,9 +38,11 @@ public GitVersionContext Create(GitVersionOptions gitVersionOptions) currentBranch = branchForCommit ?? currentBranch; } - var currentCommitTaggedVersion = this.repositoryStore.GetCurrentCommitTaggedVersion(currentCommit, configuration.TagPrefix, configuration.SemanticVersionFormat, handleDetachedBranch: currentBranch.IsDetachedHead); + bool isCurrentCommitTagged = this.taggedSemanticVersionRepository + .GetTaggedSemanticVersions(configuration.TagPrefix, configuration.SemanticVersionFormat) + .Contains(currentCommit); var numberOfUncommittedChanges = this.repositoryStore.GetNumberOfUncommittedChanges(); - return new(currentBranch, currentCommit, configuration, currentCommitTaggedVersion, numberOfUncommittedChanges); + return new(currentBranch, currentCommit, configuration, isCurrentCommitTagged, numberOfUncommittedChanges); } } diff --git a/src/GitVersion.Core/Core/IBranchRepository.cs b/src/GitVersion.Core/Core/IBranchRepository.cs index 11a74ac41c..95887c6f37 100644 --- a/src/GitVersion.Core/Core/IBranchRepository.cs +++ b/src/GitVersion.Core/Core/IBranchRepository.cs @@ -1,8 +1,10 @@ +using GitVersion.Configuration; + namespace GitVersion.Core; internal interface IBranchRepository { - IEnumerable GetMainBranches(params IBranch[] excludeBranches); + IEnumerable GetMainBranches(IGitVersionConfiguration configuration, params IBranch[] excludeBranches); - IEnumerable GetReleaseBranches(params IBranch[] excludeBranches); + IEnumerable GetReleaseBranches(IGitVersionConfiguration configuration, params IBranch[] excludeBranches); } diff --git a/src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs b/src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs index ecb4b063c1..d10496ec0d 100644 --- a/src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs +++ b/src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs @@ -4,7 +4,12 @@ namespace GitVersion.Core; internal interface ITaggedSemanticVersionRepository { - ILookup GetAllTaggedSemanticVersions(IBranch branch, EffectiveConfiguration configuration); + ILookup GetAllTaggedSemanticVersions( + IGitVersionConfiguration configuration, + EffectiveConfiguration effectiveConfiguration, + IBranch branch, + string? label, + DateTimeOffset? notOlderThan); ILookup GetTaggedSemanticVersionsOfBranch( IBranch branch, @@ -17,11 +22,13 @@ ILookup GetTaggedSemanticVersionsOfMergeTarget( SemanticVersionFormat format); ILookup GetTaggedSemanticVersionsOfMainBranches( + IGitVersionConfiguration configuration, string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches); ILookup GetTaggedSemanticVersionsOfReleaseBranches( + IGitVersionConfiguration configuration, string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches); diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index 7ce3847f4c..4ad673e6fa 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -12,9 +12,6 @@ internal class RepositoryStore : IRepositoryStore private readonly ILog log; private readonly IGitRepository repository; - private IReadOnlyList? taggedSemanticVersionsCache; - private readonly Dictionary> taggedSemanticVersionsOnBranchCache = new(); - private readonly MergeBaseFinder mergeBaseFinder; public RepositoryStore(ILog log, IGitRepository repository) @@ -194,58 +191,6 @@ public IEnumerable FindCommitBranchesWasBranchedFrom(IBranch branc } } - public SemanticVersion? GetCurrentCommitTaggedVersion(ICommit? commit, string? tagPrefix, SemanticVersionFormat format, bool handleDetachedBranch) - => this.repository.Tags - .SelectMany(tag => GetCurrentCommitSemanticVersions(commit, tagPrefix, tag, format, handleDetachedBranch)) - .Max(); - - public IReadOnlyList GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format) - { - if (this.taggedSemanticVersionsCache != null) - { - this.log.Debug($"Returning cached tagged semantic versions. TagPrefix: {tagPrefix} and Format: {format}"); - return this.taggedSemanticVersionsCache; - } - - this.log.Info($"Getting tagged semantic versions. TagPrefix: {tagPrefix} and Format: {format}"); - this.taggedSemanticVersionsCache = GetTaggedSemanticVersionsInternal().ToList(); - return this.taggedSemanticVersionsCache; - - IEnumerable GetTaggedSemanticVersionsInternal() - { - foreach (var tag in this.repository.Tags) - { - if (SemanticVersion.TryParse(tag.Name.Friendly, tagPrefix, out var semanticVersion, format)) - { - yield return new(semanticVersion, tag); - } - } - } - } - - public IReadOnlyList GetTaggedSemanticVersionsOnBranch( - IBranch branch, string? tagPrefix, SemanticVersionFormat format) - { - branch = branch.NotNull(); - - if (this.taggedSemanticVersionsOnBranchCache.TryGetValue(branch, out var onBranch)) - { - this.log.Debug($"Returning cached tagged semantic versions from '{branch.Name.Canonical}'. TagPrefix: {tagPrefix} and Format: {format}"); - return onBranch; - } - - using (this.log.IndentLog($"Getting tagged semantic versions from '{branch.Name.Canonical}'. TagPrefix: {tagPrefix} and Format: {format}")) - { - var semanticVersions = GetTaggedSemanticVersions(tagPrefix, format); - var tagsBySha = semanticVersions.Where(t => t.Tag.TargetSha != null).ToLookup(t => t.Tag.TargetSha, t => t); - - var versionTags = (branch.Commits.SelectMany(c => tagsBySha[c.Sha].Select(t => t))).ToList(); - - this.taggedSemanticVersionsOnBranchCache.Add(branch, versionTags); - return versionTags; - } - } - public IEnumerable GetCommitLog(ICommit? baseVersionSource, ICommit? currentCommit) { var filter = new CommitFilter { IncludeReachableFrom = currentCommit, ExcludeReachableFrom = baseVersionSource, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; @@ -263,18 +208,4 @@ public bool IsCommitOnBranch(ICommit? baseVersionSource, IBranch branch, ICommit public ICommit? FindMergeBase(ICommit commit, ICommit mainlineTip) => this.repository.FindMergeBase(commit, mainlineTip); public int GetNumberOfUncommittedChanges() => this.repository.GetNumberOfUncommittedChanges(); - - private IEnumerable GetCurrentCommitSemanticVersions(ICommit? commit, string? tagPrefix, ITag tag, SemanticVersionFormat versionFormat, bool handleDetachedBranch) - { - if (commit == null) - return []; - - var commitToCompare = handleDetachedBranch ? FindMergeBase(commit, tag.Commit) : commit; - - var tagName = tag.Name.Friendly; - - return Equals(tag.Commit, commitToCompare) && SemanticVersion.TryParse(tagName, tagPrefix, out var version, versionFormat) - ? [version] - : []; - } } diff --git a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs index 0a6c377d10..5af9503836 100644 --- a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs +++ b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs @@ -7,7 +7,6 @@ namespace GitVersion.Core; internal sealed class TaggedSemanticVersionRepository( ILog log, - Lazy versionContext, IGitRepository gitRepository, IBranchRepository branchRepository) : ITaggedSemanticVersionRepository @@ -20,85 +19,98 @@ internal sealed class TaggedSemanticVersionRepository( taggedSemanticVersionsCache = new(); private readonly ILog log = log.NotNull(); - private GitVersionContext VersionContext => this.versionContextLazy.Value; - private readonly Lazy versionContextLazy = versionContext.NotNull(); - private readonly IGitRepository gitRepository = gitRepository.NotNull(); private readonly IBranchRepository branchRepository = branchRepository.NotNull(); - public ILookup GetAllTaggedSemanticVersions(IBranch branch, EffectiveConfiguration configuration) + public ILookup GetAllTaggedSemanticVersions( + IGitVersionConfiguration configuration, EffectiveConfiguration effectiveConfiguration, + IBranch branch, string? label, DateTimeOffset? notOlderThan) { configuration.NotNull(); + effectiveConfiguration.NotNull(); + branch.NotNull(); IEnumerable<(ICommit Key, SemanticVersionWithTag Value)> GetElements() { - var olderThan = VersionContext.CurrentCommit.When; - var semanticVersionsOfBranch = GetTaggedSemanticVersionsOfBranch( branch: branch, - tagPrefix: configuration.TagPrefix, - format: configuration.SemanticVersionFormat + tagPrefix: effectiveConfiguration.TagPrefix, + format: effectiveConfiguration.SemanticVersionFormat ); foreach (var grouping in semanticVersionsOfBranch) { - if (grouping.Key.When > olderThan) continue; + if (grouping.Key.When > notOlderThan) continue; foreach (var semanticVersion in grouping) { - yield return new(grouping.Key, semanticVersion); + if (semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) + { + yield return new(grouping.Key, semanticVersion); + } } } - if (configuration.TrackMergeTarget) + if (effectiveConfiguration.TrackMergeTarget) { var semanticVersionsOfMergeTarget = GetTaggedSemanticVersionsOfMergeTarget( branch: branch, - tagPrefix: configuration.TagPrefix, - format: configuration.SemanticVersionFormat + tagPrefix: effectiveConfiguration.TagPrefix, + format: effectiveConfiguration.SemanticVersionFormat ); foreach (var grouping in semanticVersionsOfMergeTarget) { - if (grouping.Key.When > olderThan) continue; + if (grouping.Key.When > notOlderThan) continue; foreach (var semanticVersion in grouping) { - yield return new(grouping.Key, semanticVersion); + if (semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) + { + yield return new(grouping.Key, semanticVersion); + } } } } - if (configuration.TracksReleaseBranches) + if (effectiveConfiguration.TracksReleaseBranches) { var semanticVersionsOfReleaseBranches = GetTaggedSemanticVersionsOfReleaseBranches( - tagPrefix: configuration.TagPrefix, - format: configuration.SemanticVersionFormat, + configuration: configuration, + tagPrefix: effectiveConfiguration.TagPrefix, + format: effectiveConfiguration.SemanticVersionFormat, excludeBranches: branch ); foreach (var grouping in semanticVersionsOfReleaseBranches) { - if (grouping.Key.When > olderThan) continue; + if (grouping.Key.When > notOlderThan) continue; foreach (var semanticVersion in grouping) { - yield return new(grouping.Key, semanticVersion); + if (semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) + { + yield return new(grouping.Key, semanticVersion); + } } } } - if (!configuration.IsMainBranch && !configuration.IsReleaseBranch) + if (!effectiveConfiguration.IsMainBranch && !effectiveConfiguration.IsReleaseBranch) { var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainBranches( - tagPrefix: configuration.TagPrefix, - format: configuration.SemanticVersionFormat, + configuration: configuration, + tagPrefix: effectiveConfiguration.TagPrefix, + format: effectiveConfiguration.SemanticVersionFormat, excludeBranches: branch ); foreach (var grouping in semanticVersionsOfMainlineBranches) { - if (grouping.Key.When > olderThan) continue; + if (grouping.Key.When > notOlderThan) continue; foreach (var semanticVersion in grouping) { - yield return new(grouping.Key, semanticVersion); + if (semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) + { + yield return new(grouping.Key, semanticVersion); + } } } } @@ -189,8 +201,9 @@ public ILookup GetTaggedSemanticVersionsOfMerge } public ILookup GetTaggedSemanticVersionsOfMainBranches( - string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches) + IGitVersionConfiguration configuration, string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches) { + configuration.NotNull(); tagPrefix ??= string.Empty; excludeBranches.NotNull(); @@ -199,7 +212,7 @@ IEnumerable GetElements() using (this.log.IndentLog($"Getting tagged semantic versions of mainline branches. " + $"TagPrefix: {tagPrefix} and Format: {format}")) { - foreach (var mainlinemBranch in branchRepository.GetMainBranches(excludeBranches)) + foreach (var mainlinemBranch in branchRepository.GetMainBranches(configuration, excludeBranches)) { foreach (var semanticVersion in GetTaggedSemanticVersionsOfBranch(mainlinemBranch, tagPrefix, format).SelectMany(_ => _)) { @@ -213,8 +226,9 @@ IEnumerable GetElements() } public ILookup GetTaggedSemanticVersionsOfReleaseBranches( - string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches) + IGitVersionConfiguration configuration, string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches) { + configuration.NotNull(); tagPrefix ??= string.Empty; excludeBranches.NotNull(); @@ -223,7 +237,7 @@ IEnumerable GetElements() using (this.log.IndentLog($"Getting tagged semantic versions of release branches. " + $"TagPrefix: {tagPrefix} and Format: {format}")) { - foreach (var releaseBranch in branchRepository.GetReleaseBranches(excludeBranches)) + foreach (var releaseBranch in branchRepository.GetReleaseBranches(configuration, excludeBranches)) { foreach (var semanticVersion in GetTaggedSemanticVersionsOfBranch(releaseBranch, tagPrefix, format).SelectMany(_ => _)) { diff --git a/src/GitVersion.Core/Git/ReferenceName.cs b/src/GitVersion.Core/Git/ReferenceName.cs index 8aeb350104..601ddc1348 100644 --- a/src/GitVersion.Core/Git/ReferenceName.cs +++ b/src/GitVersion.Core/Git/ReferenceName.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; using System.Text.RegularExpressions; using GitVersion.Extensions; using GitVersion.Helpers; @@ -85,8 +84,6 @@ public bool TryGetSemanticVersion([NotNullWhen(true)] out (SemanticVersion Value { result = default; - Contract.Assume(versionPatternRegex.ToString().StartsWith('^')); - int length = 0; foreach (var branchPart in WithoutOrigin.Split(GetBranchSeparator())) { diff --git a/src/GitVersion.Core/GitVersionContext.cs b/src/GitVersion.Core/GitVersionContext.cs index ace419d104..41e7cfe9a6 100644 --- a/src/GitVersion.Core/GitVersionContext.cs +++ b/src/GitVersion.Core/GitVersionContext.cs @@ -10,7 +10,7 @@ public class GitVersionContext( IBranch currentBranch, ICommit currentCommit, IGitVersionConfiguration configuration, - SemanticVersion? currentCommitTaggedVersion, + bool isCurrentCommitTagged, int numberOfUncommittedChanges) { /// @@ -18,13 +18,11 @@ public class GitVersionContext( /// public IGitVersionConfiguration Configuration { get; } = configuration.NotNull(); - public SemanticVersion? CurrentCommitTaggedVersion { get; } = currentCommitTaggedVersion; - public IBranch CurrentBranch { get; } = currentBranch.NotNull(); public ICommit CurrentCommit { get; } = currentCommit.NotNull(); - public bool IsCurrentCommitTagged => CurrentCommitTaggedVersion != null; + public bool IsCurrentCommitTagged { get; } = isCurrentCommitTagged; public int NumberOfUncommittedChanges { get; } = numberOfUncommittedChanges; } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index ae6b261883..45a47acf32 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -98,13 +98,10 @@ GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.ICommit! commit, Git GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.ICommit! commit, System.Collections.Generic.IEnumerable? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.ICommit? baseVersionSource, GitVersion.ICommit? currentCommit) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.IBranch! currentBranch, string? commitId) -> GitVersion.ICommit? -GitVersion.Common.IRepositoryStore.GetCurrentCommitTaggedVersion(GitVersion.ICommit? commit, string? tagPrefix, GitVersion.SemanticVersionFormat format, bool handleDetachedBranch) -> GitVersion.SemanticVersion? GitVersion.Common.IRepositoryStore.GetNumberOfUncommittedChanges() -> int GitVersion.Common.IRepositoryStore.GetReleaseBranches(System.Collections.Generic.IEnumerable>! releaseBranchConfig) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetSourceBranches(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, System.Collections.Generic.IEnumerable! excludedBranches) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetSourceBranches(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, params GitVersion.IBranch![]! excludedBranches) -> System.Collections.Generic.IEnumerable! -GitVersion.Common.IRepositoryStore.GetTaggedSemanticVersions(string? tagPrefix, GitVersion.SemanticVersionFormat format) -> System.Collections.Generic.IReadOnlyList! -GitVersion.Common.IRepositoryStore.GetTaggedSemanticVersionsOnBranch(GitVersion.IBranch! branch, string? tagPrefix, GitVersion.SemanticVersionFormat format) -> System.Collections.Generic.IReadOnlyList! GitVersion.Common.IRepositoryStore.GetTargetBranch(string? targetBranchName) -> GitVersion.IBranch! GitVersion.Common.IRepositoryStore.IsCommitOnBranch(GitVersion.ICommit? baseVersionSource, GitVersion.IBranch! branch, GitVersion.ICommit! firstMatchingCommit) -> bool GitVersion.Configuration.ConfigurationExtensions @@ -119,11 +116,11 @@ GitVersion.Configuration.EffectiveConfiguration.AssemblyInformationalFormat.get GitVersion.Configuration.EffectiveConfiguration.AssemblyVersioningFormat.get -> string? GitVersion.Configuration.EffectiveConfiguration.AssemblyVersioningScheme.get -> GitVersion.Extensions.AssemblyVersioningScheme GitVersion.Configuration.EffectiveConfiguration.DeploymentMode.get -> GitVersion.VersionCalculation.DeploymentMode +GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.Configuration.IBranchConfiguration! branchConfiguration) -> void +GitVersion.Configuration.EffectiveConfiguration.PreventIncrementWhenCurrentCommitTagged.get -> bool GitVersion.Configuration.EffectiveConfiguration.RegularExpression.get -> string? GitVersion.Configuration.EffectiveConfiguration.CommitDateFormat.get -> string? GitVersion.Configuration.EffectiveConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode -GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.Configuration.IBranchConfiguration! branchConfiguration) -> void -GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Extensions.AssemblyVersioningScheme assemblyVersioningScheme, GitVersion.Extensions.AssemblyFileVersioningScheme assemblyFileVersioningScheme, string? assemblyInformationalFormat, string? assemblyVersioningFormat, string? assemblyFileVersioningFormat, GitVersion.VersionCalculation.DeploymentMode versioningMode, string? tagPrefix, string! label, string? nextVersion, GitVersion.IncrementStrategy increment, string? regularExpression, bool preventIncrementOfMergedBranchVersion, string? labelNumberPattern, bool trackMergeTarget, string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, GitVersion.VersionCalculation.CommitMessageIncrementMode commitMessageIncrementing, System.Collections.Generic.IEnumerable! versionFilters, bool tracksReleaseBranches, bool isReleaseBranch, bool isMainBranch, string? commitDateFormat, bool updateBuildNumber, GitVersion.SemanticVersionFormat semanticVersionFormat, int preReleaseWeight, int tagPreReleaseWeight) -> void GitVersion.Configuration.EffectiveConfiguration.Increment.get -> GitVersion.IncrementStrategy GitVersion.Configuration.EffectiveConfiguration.IsMainBranch.get -> bool GitVersion.Configuration.EffectiveConfiguration.IsReleaseBranch.get -> bool @@ -160,6 +157,7 @@ GitVersion.Configuration.IBranchConfiguration.Label.get -> string? GitVersion.Configuration.IBranchConfiguration.LabelNumberPattern.get -> string? GitVersion.Configuration.IBranchConfiguration.PreReleaseWeight.get -> int? GitVersion.Configuration.IBranchConfiguration.PreventIncrementOfMergedBranchVersion.get -> bool? +GitVersion.Configuration.IBranchConfiguration.PreventIncrementWhenCurrentCommitTagged.get -> bool? GitVersion.Configuration.IBranchConfiguration.RegularExpression.get -> string? GitVersion.Configuration.IBranchConfiguration.SourceBranches.get -> System.Collections.Generic.IReadOnlyCollection! GitVersion.Configuration.IBranchConfiguration.TrackMergeMessage.get -> bool? @@ -199,7 +197,7 @@ GitVersion.Configuration.IGitVersionConfiguration.Workflow.get -> string? GitVersion.Configuration.IIgnoreConfiguration GitVersion.Configuration.IIgnoreConfiguration.Before.get -> System.DateTimeOffset? GitVersion.Configuration.IIgnoreConfiguration.IsEmpty.get -> bool -GitVersion.Configuration.IIgnoreConfiguration.Shas.get -> System.Collections.Generic.IReadOnlyCollection! +GitVersion.Configuration.IIgnoreConfiguration.Shas.get -> System.Collections.Generic.IReadOnlySet! GitVersion.ConfigurationInfo GitVersion.ConfigurationInfo.ConfigurationFile -> string? GitVersion.ConfigurationInfo.ConfigurationInfo() -> void @@ -243,8 +241,7 @@ GitVersion.GitVersionContext GitVersion.GitVersionContext.Configuration.get -> GitVersion.Configuration.IGitVersionConfiguration! GitVersion.GitVersionContext.CurrentBranch.get -> GitVersion.IBranch! GitVersion.GitVersionContext.CurrentCommit.get -> GitVersion.ICommit! -GitVersion.GitVersionContext.CurrentCommitTaggedVersion.get -> GitVersion.SemanticVersion? -GitVersion.GitVersionContext.GitVersionContext(GitVersion.IBranch! currentBranch, GitVersion.ICommit! currentCommit, GitVersion.Configuration.IGitVersionConfiguration! configuration, GitVersion.SemanticVersion? currentCommitTaggedVersion, int numberOfUncommittedChanges) -> void +GitVersion.GitVersionContext.GitVersionContext(GitVersion.IBranch! currentBranch, GitVersion.ICommit! currentCommit, GitVersion.Configuration.IGitVersionConfiguration! configuration, bool isCurrentCommitTagged, int numberOfUncommittedChanges) -> void GitVersion.GitVersionContext.IsCurrentCommitTagged.get -> bool GitVersion.GitVersionContext.NumberOfUncommittedChanges.get -> int GitVersion.GitVersionCoreModule @@ -551,7 +548,6 @@ GitVersion.SemanticVersion.IncrementMode GitVersion.SemanticVersion.IncrementMode.EnsureIntegrity = 2 -> GitVersion.SemanticVersion.IncrementMode GitVersion.SemanticVersion.IncrementMode.Force = 1 -> GitVersion.SemanticVersion.IncrementMode GitVersion.SemanticVersion.IncrementMode.Standard = 0 -> GitVersion.SemanticVersion.IncrementMode -GitVersion.SemanticVersion.IncrementVersion(GitVersion.VersionField incrementStrategy) -> GitVersion.SemanticVersion! GitVersion.SemanticVersion.IsEmpty() -> bool GitVersion.SemanticVersion.IsEqualTo(GitVersion.SemanticVersion? value, bool includePreRelease = true) -> bool GitVersion.SemanticVersion.IsGreaterThan(GitVersion.SemanticVersion? value, bool includePreRelease = true) -> bool @@ -621,7 +617,7 @@ 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.SemanticVersionFormatValues(GitVersion.SemanticVersion! semver, GitVersion.Configuration.IGitVersionConfiguration! configuration, int preReleaseWeight) -> void GitVersion.SemanticVersionFormatValues.SemVer.get -> string! GitVersion.SemanticVersionFormatValues.Sha.get -> string? GitVersion.SemanticVersionFormatValues.ShortSha.get -> string? @@ -644,6 +640,7 @@ GitVersion.SemanticVersionPreReleaseTag.SemanticVersionPreReleaseTag(string! nam GitVersion.SemanticVersionPreReleaseTag.ToString(string! format) -> string! GitVersion.SemanticVersionPreReleaseTag.ToString(string? format, System.IFormatProvider? formatProvider) -> string! GitVersion.SemanticVersionWithTag +GitVersion.SemanticVersionWithTag.CompareTo(GitVersion.SemanticVersionWithTag? other) -> int GitVersion.SemanticVersionWithTag.SemanticVersionWithTag(GitVersion.SemanticVersion! Value, GitVersion.ITag! Tag) -> void GitVersion.SemanticVersionWithTag.Tag.get -> GitVersion.ITag! GitVersion.SemanticVersionWithTag.Tag.init -> void @@ -688,6 +685,8 @@ GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ContinuousDelivery = 1 -> GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ContinuousDeployment = 2 -> GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ManualDeployment = 0 -> GitVersion.VersionCalculation.DeploymentMode +GitVersion.VersionCalculation.IDeploymentModeCalculator +GitVersion.VersionCalculation.IDeploymentModeCalculator.Calculate(GitVersion.SemanticVersion! semanticVersion, GitVersion.ICommit? baseVersionSource) -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.IIncrementStrategyFinder @@ -696,13 +695,11 @@ GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForcedByCommi GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, GitVersion.ICommit![]! commits) -> GitVersion.VersionField? GitVersion.VersionCalculation.IIncrementStrategyFinder.GetMergedCommits(GitVersion.ICommit! mergeCommit, int index) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.INextVersionCalculator -GitVersion.VersionCalculation.INextVersionCalculator.FindVersion() -> GitVersion.VersionCalculation.NextVersion! +GitVersion.VersionCalculation.INextVersionCalculator.FindVersion() -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.IVariableProvider -GitVersion.VersionCalculation.IVariableProvider.GetVariablesFor(GitVersion.SemanticVersion! semanticVersion, GitVersion.Configuration.EffectiveConfiguration! configuration, GitVersion.SemanticVersion? currentCommitTaggedVersion) -> GitVersion.OutputVariables.GitVersionVariables! +GitVersion.VersionCalculation.IVariableProvider.GetVariablesFor(GitVersion.SemanticVersion! semanticVersion, GitVersion.Configuration.IGitVersionConfiguration! configuration, int preReleaseWeight) -> GitVersion.OutputVariables.GitVersionVariables! GitVersion.VersionCalculation.IVersionFilter GitVersion.VersionCalculation.IVersionFilter.Exclude(GitVersion.VersionCalculation.BaseVersion! version, out string? reason) -> bool -GitVersion.VersionCalculation.IVersionModeCalculator -GitVersion.VersionCalculation.IVersionModeCalculator.Calculate(GitVersion.VersionCalculation.NextVersion! nextVersion) -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.IVersionStrategy GitVersion.VersionCalculation.IVersionStrategy.GetBaseVersions(GitVersion.Configuration.EffectiveBranchConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.NextVersion @@ -858,19 +855,18 @@ static GitVersion.ReferenceName.FromBranchName(string! branchName) -> GitVersion static GitVersion.ReferenceName.Parse(string! canonicalName) -> GitVersion.ReferenceName! static GitVersion.ReferenceName.TryParse(out GitVersion.ReferenceName? value, string! canonicalName) -> bool static GitVersion.SemanticVersion.Parse(string! version, string? tagPrefixRegex, GitVersion.SemanticVersionFormat versionFormat = GitVersion.SemanticVersionFormat.Strict) -> GitVersion.SemanticVersion! -static GitVersion.SemanticVersion.TryParse(string! version, string? tagPrefixRegex, out GitVersion.SemanticVersion? semanticVersion, GitVersion.SemanticVersionFormat format = GitVersion.SemanticVersionFormat.Strict) -> bool static GitVersion.SemanticVersion.operator !=(GitVersion.SemanticVersion? v1, GitVersion.SemanticVersion? v2) -> bool static GitVersion.SemanticVersion.operator <(GitVersion.SemanticVersion! v1, GitVersion.SemanticVersion! v2) -> bool static GitVersion.SemanticVersion.operator <=(GitVersion.SemanticVersion! v1, GitVersion.SemanticVersion! v2) -> bool static GitVersion.SemanticVersion.operator ==(GitVersion.SemanticVersion? v1, GitVersion.SemanticVersion? v2) -> bool static GitVersion.SemanticVersion.operator >(GitVersion.SemanticVersion! v1, GitVersion.SemanticVersion! v2) -> bool static GitVersion.SemanticVersion.operator >=(GitVersion.SemanticVersion! v1, GitVersion.SemanticVersion! v2) -> bool +static GitVersion.SemanticVersion.TryParse(string! version, string? tagPrefixRegex, out GitVersion.SemanticVersion? semanticVersion, GitVersion.SemanticVersionFormat format = GitVersion.SemanticVersionFormat.Strict) -> bool static GitVersion.SemanticVersionBuildMetaData.Parse(string? buildMetaData) -> GitVersion.SemanticVersionBuildMetaData! static GitVersion.SemanticVersionBuildMetaData.implicit operator GitVersion.SemanticVersionBuildMetaData!(string! preReleaseTag) -> GitVersion.SemanticVersionBuildMetaData! static GitVersion.SemanticVersionBuildMetaData.implicit operator string?(GitVersion.SemanticVersionBuildMetaData? preReleaseTag) -> string? static GitVersion.SemanticVersionBuildMetaData.operator !=(GitVersion.SemanticVersionBuildMetaData? left, GitVersion.SemanticVersionBuildMetaData? right) -> bool static GitVersion.SemanticVersionBuildMetaData.operator ==(GitVersion.SemanticVersionBuildMetaData? left, GitVersion.SemanticVersionBuildMetaData? right) -> bool -static GitVersion.SemanticVersionPreReleaseTag.Parse(string? preReleaseTag) -> GitVersion.SemanticVersionPreReleaseTag! static GitVersion.SemanticVersionPreReleaseTag.implicit operator GitVersion.SemanticVersionPreReleaseTag!(string? preReleaseTag) -> GitVersion.SemanticVersionPreReleaseTag! static GitVersion.SemanticVersionPreReleaseTag.implicit operator string?(GitVersion.SemanticVersionPreReleaseTag? preReleaseTag) -> string? static GitVersion.SemanticVersionPreReleaseTag.operator !=(GitVersion.SemanticVersionPreReleaseTag? left, GitVersion.SemanticVersionPreReleaseTag? right) -> bool @@ -879,6 +875,7 @@ static GitVersion.SemanticVersionPreReleaseTag.operator <=(GitVersion.SemanticVe static GitVersion.SemanticVersionPreReleaseTag.operator ==(GitVersion.SemanticVersionPreReleaseTag? left, GitVersion.SemanticVersionPreReleaseTag? right) -> bool static GitVersion.SemanticVersionPreReleaseTag.operator >(GitVersion.SemanticVersionPreReleaseTag? left, GitVersion.SemanticVersionPreReleaseTag? right) -> bool static GitVersion.SemanticVersionPreReleaseTag.operator >=(GitVersion.SemanticVersionPreReleaseTag? left, GitVersion.SemanticVersionPreReleaseTag? right) -> bool +static GitVersion.SemanticVersionPreReleaseTag.Parse(string? preReleaseTag) -> GitVersion.SemanticVersionPreReleaseTag! static GitVersion.VersionCalculation.NextVersion.operator !=(GitVersion.VersionCalculation.NextVersion! left, GitVersion.VersionCalculation.NextVersion! right) -> bool static GitVersion.VersionCalculation.NextVersion.operator <(GitVersion.VersionCalculation.NextVersion! left, GitVersion.VersionCalculation.NextVersion! right) -> bool static GitVersion.VersionCalculation.NextVersion.operator <=(GitVersion.VersionCalculation.NextVersion! left, GitVersion.VersionCalculation.NextVersion! right) -> bool diff --git a/src/GitVersion.Core/SemVer/SemanticVersion.cs b/src/GitVersion.Core/SemVer/SemanticVersion.cs index 394f9f11dd..02a63fbcd7 100644 --- a/src/GitVersion.Core/SemVer/SemanticVersion.cs +++ b/src/GitVersion.Core/SemVer/SemanticVersion.cs @@ -144,7 +144,8 @@ public override int GetHashCode() return v1.CompareTo(v2) < 0; } - public static SemanticVersion Parse(string version, string? tagPrefixRegex, SemanticVersionFormat versionFormat = SemanticVersionFormat.Strict) + public static SemanticVersion Parse( + string version, string? tagPrefixRegex, SemanticVersionFormat versionFormat = SemanticVersionFormat.Strict) { if (!TryParse(version, tagPrefixRegex, out var semanticVersion, versionFormat)) throw new WarningException($"Failed to parse {version} into a Semantic Version"); @@ -152,7 +153,8 @@ public static SemanticVersion Parse(string version, string? tagPrefixRegex, Sema return semanticVersion; } - public static bool TryParse(string version, string? tagPrefixRegex, [NotNullWhen(true)] out SemanticVersion? semanticVersion, SemanticVersionFormat format = SemanticVersionFormat.Strict) + public static bool TryParse(string version, string? tagPrefixRegex, + [NotNullWhen(true)] out SemanticVersion? semanticVersion, SemanticVersionFormat format = SemanticVersionFormat.Strict) { var match = Regex.Match(version, $"^({tagPrefixRegex})(?.*)$"); @@ -327,64 +329,6 @@ public string ToString(string? format, IFormatProvider? formatProvider) } } - public SemanticVersion IncrementVersion(VersionField incrementStrategy) - => IncrementVersion(incrementStrategy, null, isMainBranchRelease: true); - - private SemanticVersion IncrementVersion(VersionField incrementStrategy, string? label, bool isMainBranchRelease) - { - var major = Major; - var minor = Minor; - var patch = Patch; - - if (isMainBranchRelease || !PreReleaseTag.HasTag()) - { - switch (incrementStrategy) - { - case VersionField.None: - break; - case VersionField.Major: - major++; - minor = 0; - patch = 0; - break; - case VersionField.Minor: - minor++; - patch = 0; - break; - case VersionField.Patch: - patch++; - break; - default: - throw new ArgumentOutOfRangeException(nameof(incrementStrategy)); - } - } - - string preReleaseTagName = string.Empty; - long? preReleaseTagNumber = null; - - if (!isMainBranchRelease) - { - if (PreReleaseTag.HasTag()) - { - preReleaseTagNumber = PreReleaseTag.Number + 1; - preReleaseTagName = PreReleaseTag.Name; - } - else - { - preReleaseTagNumber = 1; - preReleaseTagName = label ?? string.Empty; - } - } - - return new(this) - { - Major = major, - Minor = minor, - Patch = patch, - PreReleaseTag = new(preReleaseTagName, preReleaseTagNumber, true) - }; - } - public SemanticVersion Increment(VersionField incrementStrategy, string? label) => Increment(incrementStrategy, label, mode: IncrementMode.Standard); diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IDeploymentModeCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IDeploymentModeCalculator.cs new file mode 100644 index 0000000000..e4d16d3710 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IDeploymentModeCalculator.cs @@ -0,0 +1,6 @@ +namespace GitVersion.VersionCalculation; + +public interface IDeploymentModeCalculator +{ + SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseVersionSource); +} diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/INextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/INextVersionCalculator.cs index b1ee00577d..03bc8082db 100644 --- a/src/GitVersion.Core/VersionCalculation/Abstractions/INextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/INextVersionCalculator.cs @@ -2,5 +2,5 @@ namespace GitVersion.VersionCalculation; public interface INextVersionCalculator { - NextVersion FindVersion(); + SemanticVersion FindVersion(); } diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IVariableProvider.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IVariableProvider.cs index 7276ffe793..cb848efc23 100644 --- a/src/GitVersion.Core/VersionCalculation/Abstractions/IVariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IVariableProvider.cs @@ -6,6 +6,5 @@ namespace GitVersion.VersionCalculation; public interface IVariableProvider { GitVersionVariables GetVariablesFor( - SemanticVersion semanticVersion, EffectiveConfiguration configuration, SemanticVersion? currentCommitTaggedVersion - ); + SemanticVersion semanticVersion, IGitVersionConfiguration configuration, int preReleaseWeight); } diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IVersionModeCalculator.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IVersionModeCalculator.cs deleted file mode 100644 index e0df95e105..0000000000 --- a/src/GitVersion.Core/VersionCalculation/Abstractions/IVersionModeCalculator.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace GitVersion.VersionCalculation; - -public interface IVersionModeCalculator -{ - SemanticVersion Calculate(NextVersion nextVersion); -} diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs index bc72f81b6b..1da7195708 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs @@ -4,7 +4,7 @@ namespace GitVersion; -public class SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfiguration configuration) +public class SemanticVersionFormatValues(SemanticVersion semver, IGitVersionConfiguration configuration, int preReleaseWeight) { public string Major => semver.Major.ToString(); @@ -22,7 +22,8 @@ public class SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfig public string PreReleaseNumber => semver.PreReleaseTag.Number?.ToString() ?? string.Empty; - public string WeightedPreReleaseNumber => GetWeightedPreReleaseNumber(); + public string WeightedPreReleaseNumber => semver.PreReleaseTag.Number.HasValue + ? $"{semver.PreReleaseTag.Number.Value + preReleaseWeight}" : $"{configuration.TagPreReleaseWeight}"; public string BuildMetaData => semver.BuildMetaData.ToString(); @@ -32,9 +33,9 @@ public class SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfig public string SemVer => semver.ToString(); - public string? AssemblySemVer => semver.GetAssemblyVersion(configuration.AssemblyVersioningScheme); + public string? AssemblySemVer => semver.GetAssemblyVersion(configuration.AssemblyVersioningScheme!.Value); - public string? AssemblyFileSemVer => semver.GetAssemblyFileVersion(configuration.AssemblyFileVersioningScheme); + public string? AssemblyFileSemVer => semver.GetAssemblyFileVersion(configuration.AssemblyFileVersioningScheme!.Value); public string FullSemVer => semver.ToString("f"); @@ -55,14 +56,4 @@ public class SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfig public string CommitsSinceVersionSource => semver.BuildMetaData.CommitsSinceVersionSource.ToString(CultureInfo.InvariantCulture); public string UncommittedChanges => semver.BuildMetaData.UncommittedChanges.ToString(CultureInfo.InvariantCulture); - - private string GetWeightedPreReleaseNumber() - { - var weightedPreReleaseNumber = - semver.PreReleaseTag.HasTag() ? (semver.PreReleaseTag.Number + configuration.PreReleaseWeight).ToString() : null; - - return weightedPreReleaseNumber.IsNullOrEmpty() - ? $"{configuration.TagPreReleaseWeight}" - : weightedPreReleaseNumber; - } } diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionWithTag.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionWithTag.cs index f15685d2b3..84a888cae1 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionWithTag.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionWithTag.cs @@ -1,6 +1,8 @@ namespace GitVersion; -public sealed record SemanticVersionWithTag(SemanticVersion Value, ITag Tag) +public sealed record SemanticVersionWithTag(SemanticVersion Value, ITag Tag) : IComparable { + public int CompareTo(SemanticVersionWithTag? other) => Value.CompareTo(other?.Value); + public override string ToString() => $"{Tag} | {Tag.Commit} | {Value}"; } diff --git a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs index 03b86e7fa8..0cb26fa7a7 100644 --- a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs @@ -5,29 +5,17 @@ namespace GitVersion.VersionCalculation; -internal class VariableProvider(IEnvironment environment) : IVariableProvider +internal sealed class VariableProvider(IEnvironment environment) : IVariableProvider { private readonly IEnvironment environment = environment.NotNull(); public GitVersionVariables GetVariablesFor( - SemanticVersion semanticVersion, EffectiveConfiguration configuration, SemanticVersion? currentCommitTaggedVersion) + SemanticVersion semanticVersion, IGitVersionConfiguration configuration, int preReleaseWeight) { semanticVersion.NotNull(); configuration.NotNull(); - if (semanticVersion.CompareTo(currentCommitTaggedVersion) == 0) - { - // Will always be 0, don't bother with the +0 on tags - semanticVersion = new(semanticVersion) - { - BuildMetaData = new(semanticVersion.BuildMetaData) - { - CommitsSinceTag = null - } - }; - } - - var semverFormatValues = new SemanticVersionFormatValues(semanticVersion, configuration); + var semverFormatValues = new SemanticVersionFormatValues(semanticVersion, configuration, preReleaseWeight); var informationalVersion = CheckAndFormatString( configuration.AssemblyInformationalFormat, diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs index 8a19d73e5d..363f39584a 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs @@ -10,9 +10,9 @@ public void RegisterTypes(IServiceCollection services) services.AddModule(new VersionStrategyModule()); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs index a493c538ed..8e90c0e432 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs @@ -1,53 +1,40 @@ -using System.Diagnostics.Contracts; using GitVersion.Common; using GitVersion.Logging; namespace GitVersion.VersionCalculation; internal sealed class ContinuousDeliveryVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IDeploymentModeCalculator { - public SemanticVersion Calculate(NextVersion nextVersion) + public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseVersionSource) { using (this.log.IndentLog("Using continuous delivery workflow to calculate the incremented version.")) { - var preReleaseTag = nextVersion.IncrementedVersion.PreReleaseTag; + var preReleaseTag = semanticVersion.PreReleaseTag; if (!preReleaseTag.HasTag() || !preReleaseTag.Number.HasValue) { throw new WarningException("Continuous delivery requires a pre-release tag."); } - return CalculateInternal(nextVersion); + return CalculateInternal(semanticVersion, baseVersionSource); } } - private SemanticVersion CalculateInternal(NextVersion nextVersion) + private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { - if (ShouldTakeIncrementedVersion(nextVersion)) - { - var semanticVersion = CalculateIncrementedVersion(nextVersion); - - Contract.Assume(semanticVersion.PreReleaseTag.Number.HasValue); - Contract.Assume(semanticVersion.BuildMetaData.CommitsSinceTag.HasValue); - - return new(semanticVersion) - { - PreReleaseTag = new(semanticVersion.PreReleaseTag) - { - Number = semanticVersion.PreReleaseTag.Number.Value + semanticVersion.BuildMetaData.CommitsSinceTag - 1 - }, - BuildMetaData = new(semanticVersion.BuildMetaData) - { - CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value, - CommitsSinceTag = null - } - }; - } + var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - var baseVersionBuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource); - return new(nextVersion.BaseVersion.GetSemanticVersion()) + return new SemanticVersion(semanticVersion) { - BuildMetaData = baseVersionBuildMetaData + PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag) + { + Number = semanticVersion.PreReleaseTag.Number!.Value + buildMetaData.CommitsSinceTag - 1 + }, + BuildMetaData = new SemanticVersionBuildMetaData(buildMetaData) + { + CommitsSinceVersionSource = buildMetaData.CommitsSinceTag!.Value, + CommitsSinceTag = null + } }; } } diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs index bd8c4b5f2f..7ed5b72042 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs @@ -1,50 +1,29 @@ -using System.Diagnostics.Contracts; using GitVersion.Common; using GitVersion.Logging; namespace GitVersion.VersionCalculation; internal sealed class ContinuousDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IDeploymentModeCalculator { - public SemanticVersion Calculate(NextVersion nextVersion) + public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseVersionSource) { using (this.log.IndentLog("Using continuous deployment workflow to calculate the incremented version.")) { - return CalculateInternal(nextVersion); + return CalculateInternal(semanticVersion, baseVersionSource); } } - private SemanticVersion CalculateInternal(NextVersion nextVersion) + private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { - if (ShouldTakeIncrementedVersion(nextVersion)) - { - var semanticVersion = CalculateIncrementedVersion(nextVersion); - - Contract.Assume(semanticVersion.PreReleaseTag.Number.HasValue); - Contract.Assume(semanticVersion.BuildMetaData.CommitsSinceTag.HasValue); - - return new(semanticVersion) - { - PreReleaseTag = SemanticVersionPreReleaseTag.Empty, - BuildMetaData = new(semanticVersion.BuildMetaData) - { - CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value, - CommitsSinceTag = null - } - }; - } - - var baseVersionBuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource); - - Contract.Assume(baseVersionBuildMetaData.CommitsSinceTag.HasValue); + var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - return new(nextVersion.BaseVersion.GetSemanticVersion()) + return new SemanticVersion(semanticVersion) { PreReleaseTag = SemanticVersionPreReleaseTag.Empty, - BuildMetaData = new(baseVersionBuildMetaData) + BuildMetaData = new SemanticVersionBuildMetaData(buildMetaData) { - CommitsSinceVersionSource = baseVersionBuildMetaData.CommitsSinceTag.Value, + CommitsSinceVersionSource = buildMetaData.CommitsSinceTag!.Value, CommitsSinceTag = null } }; diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs index d6d7d9a197..842bc6ad74 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs @@ -4,26 +4,23 @@ namespace GitVersion.VersionCalculation; internal sealed class ManualDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IDeploymentModeCalculator { - public SemanticVersion Calculate(NextVersion nextVersion) + public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseVersionSource) { using (this.log.IndentLog("Using manual deployment workflow to calculate the incremented version.")) { - return CalculateInternal(nextVersion); + return CalculateInternal(semanticVersion, baseVersionSource); } } - private SemanticVersion CalculateInternal(NextVersion nextVersion) + private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { - if (ShouldTakeIncrementedVersion(nextVersion)) - { - return CalculateIncrementedVersion(nextVersion); - } + var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - return new(nextVersion.BaseVersion.GetSemanticVersion()) + return new SemanticVersion(semanticVersion) { - BuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource) + BuildMetaData = buildMetaData }; } } diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs index 5c20357243..b2f2a8130e 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using GitVersion.Configuration; +using GitVersion.Core; using GitVersion.Extensions; using GitVersion.Logging; @@ -9,10 +10,11 @@ namespace GitVersion.VersionCalculation; internal class NextVersionCalculator( ILog log, Lazy versionContext, - IEnumerable versionModeCalculators, + IEnumerable deploymentModeCalculators, IEnumerable versionStrategies, IEffectiveBranchConfigurationFinder effectiveBranchConfigurationFinder, - IIncrementStrategyFinder incrementStrategyFinder) + IIncrementStrategyFinder incrementStrategyFinder, + ITaggedSemanticVersionRepository taggedSemanticVersionRepository) : INextVersionCalculator { private readonly ILog log = log.NotNull(); @@ -23,30 +25,122 @@ internal class NextVersionCalculator( private GitVersionContext Context => this.versionContext.Value; - public virtual NextVersion FindVersion() + public virtual SemanticVersion FindVersion() { - this.log.Info($"Running against branch: {Context.CurrentBranch} ({Context.CurrentCommit?.ToString() ?? "-"})"); - if (Context.IsCurrentCommitTagged) + this.log.Info($"Running against branch: {Context.CurrentBranch} ({Context.CurrentCommit.ToString() ?? "-"})"); + + var branchConfiguration = Context.Configuration.GetBranchConfiguration(Context.CurrentBranch); + EffectiveConfiguration effectiveConfiguration = new(Context.Configuration, branchConfiguration); + + bool someBranchRelatedPropertiesMightBeNotKnown = branchConfiguration.Increment == IncrementStrategy.Inherit; + + if (Context.IsCurrentCommitTagged && !someBranchRelatedPropertiesMightBeNotKnown && effectiveConfiguration.PreventIncrementWhenCurrentCommitTagged) { - this.log.Info($"Current commit is tagged with version {Context.CurrentCommitTaggedVersion}, version calculation is for meta data only."); + var allTaggedSemanticVersions = taggedSemanticVersionRepository.GetAllTaggedSemanticVersions( + Context.Configuration, effectiveConfiguration, Context.CurrentBranch, null, Context.CurrentCommit.When + ); + var taggedSemanticVersionsOfCurrentCommit = allTaggedSemanticVersions[Context.CurrentCommit].ToList(); + + SemanticVersion? value; + if (TryGetSemanticVersion(effectiveConfiguration, taggedSemanticVersionsOfCurrentCommit, out value)) + { + return value; + } } - var nextVersion = CalculateNextVersion(Context.CurrentBranch, Context.Configuration); - var incrementedVersion = CalculateIncrementedVersion(nextVersion.Configuration.DeploymentMode, nextVersion); + NextVersion nextVersion = CalculateNextVersion(Context.CurrentBranch, Context.Configuration); + + if (Context.IsCurrentCommitTagged && someBranchRelatedPropertiesMightBeNotKnown && nextVersion.Configuration.PreventIncrementWhenCurrentCommitTagged) + { + var allTaggedSemanticVersions = taggedSemanticVersionRepository.GetAllTaggedSemanticVersions( + Context.Configuration, nextVersion.Configuration, Context.CurrentBranch, null, Context.CurrentCommit.When + ); + var taggedSemanticVersionsOfCurrentCommit = allTaggedSemanticVersions[Context.CurrentCommit].ToList(); + + SemanticVersion? value; + if (TryGetSemanticVersion(nextVersion.Configuration, taggedSemanticVersionsOfCurrentCommit, out value)) + { + return value; + } + } + + var semanticVersion = CalculateSemanticVersion( + deploymentMode: nextVersion.Configuration.DeploymentMode, + semanticVersion: nextVersion.IncrementedVersion, + baseVersionSource: nextVersion.BaseVersion.BaseVersionSource + ); + + var ignore = Context.Configuration.Ignore; + var alternativeSemanticVersion = taggedSemanticVersionRepository.GetTaggedSemanticVersionsOfBranch( + nextVersion.BranchConfiguration.Branch, Context.Configuration.TagPrefix, Context.Configuration.SemanticVersionFormat + ).Where(element => element.Key.When <= Context.CurrentCommit.When + && !(element.Key.When <= ignore.Before) && !ignore.Shas.Contains(element.Key.Sha) + ).SelectMany(element => element).Max()?.Value; + + if (alternativeSemanticVersion is not null + && semanticVersion.IsLessThan(alternativeSemanticVersion, includePreRelease: false)) + { + semanticVersion = new SemanticVersion(semanticVersion) + { + Major = alternativeSemanticVersion.Major, + Minor = alternativeSemanticVersion.Minor, + Patch = alternativeSemanticVersion.Patch + }; + } + + return semanticVersion; + } + + private bool TryGetSemanticVersion( + EffectiveConfiguration effectiveConfiguration, + IReadOnlyCollection taggedSemanticVersionsOfCurrentCommit, + [NotNullWhen(true)] out SemanticVersion? result) + { + result = null; + + string? label = effectiveConfiguration.GetBranchSpecificLabel(Context.CurrentBranch.Name, null); + SemanticVersionWithTag? currentCommitTaggedVersion = taggedSemanticVersionsOfCurrentCommit + .Where(element => element.Value.IsMatchForBranchSpecificLabel(label)).Max(); + + if (currentCommitTaggedVersion is not null) + { + SemanticVersionBuildMetaData semanticVersionBuildMetaData = new( + versionSourceSha: Context.CurrentCommit.Sha, + commitsSinceTag: null, + branch: Context.CurrentBranch.Name.Friendly, + commitSha: Context.CurrentCommit.Sha, + commitShortSha: Context.CurrentCommit.Id.ToString(7), + commitDate: Context.CurrentCommit?.When, + numberOfUnCommittedChanges: Context.NumberOfUncommittedChanges + ); + + SemanticVersionPreReleaseTag preReleaseTag = currentCommitTaggedVersion.Value.PreReleaseTag; + if (effectiveConfiguration.DeploymentMode == DeploymentMode.ContinuousDeployment) + { + preReleaseTag = SemanticVersionPreReleaseTag.Empty; + } - return new(incrementedVersion, nextVersion.BaseVersion, nextVersion.BranchConfiguration); + result = new SemanticVersion(currentCommitTaggedVersion.Value) + { + PreReleaseTag = preReleaseTag, + BuildMetaData = semanticVersionBuildMetaData + }; + } + + return result is not null; } - private SemanticVersion CalculateIncrementedVersion(DeploymentMode versioningMode, NextVersion nextVersion) + private SemanticVersion CalculateSemanticVersion( + DeploymentMode deploymentMode, SemanticVersion semanticVersion, ICommit? baseVersionSource) { - IVersionModeCalculator calculator = versioningMode switch + IDeploymentModeCalculator deploymentModeCalculator = deploymentMode switch { - DeploymentMode.ManualDeployment => versionModeCalculators.SingleOfType(), - DeploymentMode.ContinuousDelivery => versionModeCalculators.SingleOfType(), - DeploymentMode.ContinuousDeployment => versionModeCalculators.SingleOfType(), - _ => throw new InvalidEnumArgumentException(nameof(versioningMode), (int)versioningMode, typeof(DeploymentMode)), + DeploymentMode.ManualDeployment => deploymentModeCalculators.SingleOfType(), + DeploymentMode.ContinuousDelivery => deploymentModeCalculators.SingleOfType(), + DeploymentMode.ContinuousDeployment => deploymentModeCalculators.SingleOfType(), + _ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(DeploymentMode)) }; - return calculator.Calculate(nextVersion); + return deploymentModeCalculator.Calculate(semanticVersion, baseVersionSource); } private NextVersion CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) @@ -192,27 +286,30 @@ private SemanticVersion GetIncrementedVersion(EffectiveBranchConfiguration confi { if (baseVersion is BaseVersionV2 baseVersionV2) { + SemanticVersion result; if (baseVersion.ShouldIncrement) { - SemanticVersion result = baseVersionV2.GetSemanticVersion().Increment( + result = baseVersionV2.GetSemanticVersion().Increment( baseVersionV2.Increment, baseVersionV2.Label, baseVersionV2.ForceIncrement ); - - if (result.IsLessThan(baseVersionV2.AlternativeSemanticVersion, includePreRelease: false)) - { - result = new(result) - { - Major = baseVersionV2.AlternativeSemanticVersion!.Major, - Minor = baseVersionV2.AlternativeSemanticVersion.Minor, - Patch = baseVersionV2.AlternativeSemanticVersion.Patch - }; - } - return result; } else { - return baseVersion.GetSemanticVersion(); + result = baseVersion.GetSemanticVersion(); } + + if (baseVersionV2.AlternativeSemanticVersion is not null + && result.IsLessThan(baseVersionV2.AlternativeSemanticVersion, includePreRelease: false)) + { + return new SemanticVersion(result) + { + Major = baseVersionV2.AlternativeSemanticVersion.Major, + Minor = baseVersionV2.AlternativeSemanticVersion.Minor, + Patch = baseVersionV2.AlternativeSemanticVersion.Patch + }; + } + + return result; } else { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs deleted file mode 100644 index b844c82e64..0000000000 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs +++ /dev/null @@ -1,80 +0,0 @@ -using GitVersion.Common; -using GitVersion.Extensions; -using GitVersion.Logging; - -namespace GitVersion.VersionCalculation; - -internal abstract class NonTrunkBasedVersionCalculatorBase(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) -{ - protected readonly ILog log = log.NotNull(); - protected readonly IRepositoryStore repositoryStore = repositoryStore.NotNull(); - private readonly Lazy versionContext = versionContext.NotNull(); - - protected GitVersionContext Context => this.versionContext.Value; - - protected bool ShouldTakeIncrementedVersion(NextVersion nextVersion) - { - nextVersion.NotNull(); - - // 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 is null - || nextVersion.BaseVersion.SemanticVersion != Context.CurrentCommitTaggedVersion; - // - } - - protected SemanticVersion CalculateIncrementedVersion(NextVersion nextVersion) - { - //// - // TODO: We need to consider somehow the IGitVersionConfiguration::Ignore property here!! - var semanticVersionWithTag = this.repositoryStore.GetTaggedSemanticVersionsOnBranch( - nextVersion.BranchConfiguration.Branch, Context.Configuration.TagPrefix, 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(semanticVersionWithTag.Value) - { - PreReleaseTag = new(nextVersion.IncrementedVersion.PreReleaseTag), - BuildMetaData = CreateVersionBuildMetaData(nextVersion.BaseVersion.BaseVersionSource) - }; - } - - return new(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( - 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/VersionCalculators/VersionCalculatorBase.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/VersionCalculatorBase.cs new file mode 100644 index 0000000000..b6115a2cd6 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/VersionCalculatorBase.cs @@ -0,0 +1,40 @@ +using GitVersion.Common; +using GitVersion.Extensions; +using GitVersion.Logging; + +namespace GitVersion.VersionCalculation; + +internal abstract class VersionCalculatorBase(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) +{ + protected readonly ILog log = log.NotNull(); + protected readonly IRepositoryStore repositoryStore = repositoryStore.NotNull(); + private readonly Lazy versionContext = versionContext.NotNull(); + + protected GitVersionContext Context => this.versionContext.Value; + + protected SemanticVersionBuildMetaData CreateVersionBuildMetaData(ICommit? baseVersionSource) + { + var commitLogs = this.repositoryStore.GetCommitLog(baseVersionSource, Context.CurrentCommit); + + var ignore = Context.Configuration.Ignore; + if (!ignore.IsEmpty) + { + commitLogs = commitLogs + .Where(c => ignore.Before is null || (c.When > ignore.Before && !ignore.Shas.Contains(c.Sha))); + } + var 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/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs index aee6524a66..348a7a6a82 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs @@ -17,7 +17,7 @@ public override IEnumerable GetBaseVersions(EffectiveBranchConfigur var contextConfiguration = Context.Configuration; var nextVersion = contextConfiguration.NextVersion; - if (!nextVersion.IsNullOrEmpty() && !Context.IsCurrentCommitTagged) + if (!nextVersion.IsNullOrEmpty()) { var semanticVersion = SemanticVersion.Parse(nextVersion, contextConfiguration.TagPrefix, contextConfiguration.SemanticVersionFormat); yield return new("NextVersion in GitVersion configuration file", false, semanticVersion, null, null); diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs index 6fedc16132..1e3e7232f0 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs @@ -24,15 +24,13 @@ private IEnumerable GetTaggedSemanticVersions(EffectiveB var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null); var taggedSemanticVersions = taggedSemanticVersionRepository - .GetAllTaggedSemanticVersions(Context.CurrentBranch, configuration.Value).SelectMany(element => element) + .GetAllTaggedSemanticVersions(Context.Configuration, configuration.Value, Context.CurrentBranch, label, Context.CurrentCommit.When) + .SelectMany(element => element) .Distinct().ToArray(); foreach (var semanticVersion in taggedSemanticVersions) { - if (semanticVersion.Value.IsMatchForBranchSpecificLabel(label)) - { - yield return semanticVersion; - } + yield return semanticVersion; } } diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs index 4a9bc16a63..5b6bbbcc02 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs @@ -72,7 +72,7 @@ public override IEnumerable GetBaseVersions(EffectiveBranchConfigur var iteration = CreateIteration(branchName: Context.CurrentBranch.Name, configuration: configuration.Value); var taggedSemanticVersions = taggedSemanticVersionRepository.GetAllTaggedSemanticVersions( - Context.CurrentBranch, configuration.Value + Context.Configuration, configuration.Value, Context.CurrentBranch, null, Context.CurrentCommit.When ); var targetLabel = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null); @@ -121,7 +121,7 @@ private bool IterateOverCommitsRecursive( configuration = effectiveConfigurationWasBranchedFrom.Value; branchName = effectiveConfigurationWasBranchedFrom.Branch.Name; taggedSemanticVersions = taggedSemanticVersionRepository.GetAllTaggedSemanticVersions( - effectiveConfigurationWasBranchedFrom.Branch, effectiveConfigurationWasBranchedFrom.Value + Context.Configuration, effectiveConfigurationWasBranchedFrom.Value, effectiveConfigurationWasBranchedFrom.Branch, null, Context.CurrentCommit.When ); } diff --git a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj index 2f1399aa4a..ed6532b5d6 100644 --- a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj +++ b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj @@ -1,4 +1,4 @@ - + @@ -21,7 +21,6 @@ - diff --git a/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs b/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs index a76b55e0c0..04c0a2b193 100644 --- a/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs +++ b/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs @@ -38,7 +38,9 @@ public void ShouldCreateAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo(strin var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile); - var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null); + + var variables = this.variableProvider.GetVariablesFor( + SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); assemblyInfoFileUpdater.Execute(variables, new(workingDir, true, assemblyInfoFile)); @@ -55,7 +57,7 @@ public void ShouldCreateAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo var assemblyInfoFile = PathHelper.Combine("src", "Project", "Properties", $"VersionAssemblyInfo.{fileExtension}"); var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile); var variables = this.variableProvider.GetVariablesFor( - SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null + SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0 ); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); @@ -75,7 +77,7 @@ public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInf "AssemblyInfo." + fileExtension, PathHelper.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension) }; - var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null); + var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); assemblyInfoFileUpdater.Execute(variables, new(workingDir, true, [.. assemblyInfoFiles])); @@ -96,7 +98,7 @@ public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile); var variables = this.variableProvider.GetVariablesFor( - SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null + SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0 ); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); @@ -113,7 +115,7 @@ public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssembly const string assemblyInfoFile = "VersionAssemblyInfo.js"; var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile); var variables = this.variableProvider.GetVariablesFor( - SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null + SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0 ); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); @@ -129,7 +131,7 @@ public void ShouldStartSearchFromWorkingDirectory() var workingDir = Path.GetTempPath(); string[] assemblyInfoFiles = []; var variables = this.variableProvider.GetVariablesFor( - SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null + SemanticVersion.Parse("1.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0 ); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem); @@ -450,8 +452,8 @@ private void VerifyAssemblyInfoFile( this.fileSystem.ReadAllText(fileName).Returns(assemblyFileContent); }); - var configuration = new TestEffectiveConfiguration(versioningScheme); - var variables = this.variableProvider.GetVariablesFor(version, configuration, null); + var configuration = EmptyConfigurationBuilder.New.WithAssemblyVersioningScheme(versioningScheme).Build(); + var variables = this.variableProvider.GetVariablesFor(version, configuration, 0); verify?.Invoke(this.fileSystem, variables); } diff --git a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs index d2531f8044..ddcdac7477 100644 --- a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs +++ b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.Output.GitVersionInfo; @@ -37,7 +38,7 @@ public void ShouldCreateFile(string fileExtension) var fileSystem = sp.GetRequiredService(); var variableProvider = sp.GetRequiredService(); - var variables = variableProvider.GetVariablesFor(semanticVersion, new TestEffectiveConfiguration(), null); + var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); using var generator = sp.GetRequiredService(); generator.Execute(variables, new(directory, fileName, fileExtension)); diff --git a/src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs b/src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs index 4d93914331..38b1dc6ca1 100644 --- a/src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs +++ b/src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs @@ -144,7 +144,7 @@ public void CannotUpdateProjectFileWithoutAPropertyGroup(string xml) public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement(string xml) { var variables = this.variableProvider.GetVariablesFor( - SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null + SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0 ); var xmlRoot = XElement.Parse(xml); variables.AssemblySemVer.ShouldNotBeNull(); @@ -172,7 +172,7 @@ public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement(string x )] public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string xml) { - var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null); + var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0); var xmlRoot = XElement.Parse(xml); variables.AssemblySemVer.ShouldNotBeNull(); ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer); @@ -202,7 +202,7 @@ public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string )] public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLastElement(string xml) { - var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null); + var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0); var xmlRoot = XElement.Parse(xml); variables.AssemblySemVer.ShouldNotBeNull(); ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer); @@ -233,7 +233,7 @@ public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLas )] public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsModified(string xml) { - var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), new TestEffectiveConfiguration(), null); + var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", ConfigurationConstants.DefaultTagPrefix), EmptyConfigurationBuilder.New.Build(), 0); var xmlRoot = XElement.Parse(xml); variables.AssemblySemVer.ShouldNotBeNull(); ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer); @@ -305,8 +305,8 @@ private void VerifyAssemblyInfoFile( this.fileSystem.ReadAllText(fileName).Returns(projectFileContent); }); - var configuration = new TestEffectiveConfiguration(versioningScheme); - var variables = this.variableProvider.GetVariablesFor(version, configuration, null); + var configuration = EmptyConfigurationBuilder.New.WithAssemblyVersioningScheme(versioningScheme).Build(); + var variables = this.variableProvider.GetVariablesFor(version, configuration, 0); verify?.Invoke(this.fileSystem, variables); } diff --git a/src/GitVersion.Output.Tests/Output/WixFileTests.cs b/src/GitVersion.Output.Tests/Output/WixFileTests.cs index 8537024ff4..2efa241867 100644 --- a/src/GitVersion.Output.Tests/Output/WixFileTests.cs +++ b/src/GitVersion.Output.Tests/Output/WixFileTests.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Helpers; using GitVersion.Logging; @@ -32,8 +33,6 @@ public void UpdateWixVersionFile() } }; - var configuration = new TestEffectiveConfiguration(); - var stringBuilder = new StringBuilder(); void Action(string s) => stringBuilder.AppendLine(s); @@ -44,7 +43,7 @@ public void UpdateWixVersionFile() var fileSystem = sp.GetRequiredService(); var variableProvider = sp.GetRequiredService(); - var versionVariables = variableProvider.GetVariablesFor(semVer, configuration, null); + var versionVariables = variableProvider.GetVariablesFor(semVer, EmptyConfigurationBuilder.New.Build(), 0); using var wixVersionFileUpdater = sp.GetRequiredService(); @@ -74,8 +73,6 @@ public void UpdateWixVersionFileWhenFileAlreadyExists() } }; - var configuration = new TestEffectiveConfiguration(); - var stringBuilder = new StringBuilder(); void Action(string s) => stringBuilder.AppendLine(s); @@ -86,7 +83,7 @@ public void UpdateWixVersionFileWhenFileAlreadyExists() var fileSystem = sp.GetRequiredService(); var variableProvider = sp.GetRequiredService(); - var versionVariables = variableProvider.GetVariablesFor(semVer, configuration, null); + var versionVariables = variableProvider.GetVariablesFor(semVer, EmptyConfigurationBuilder.New.Build(), 0); using var wixVersionFileUpdater = sp.GetRequiredService();