diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index f4f6bb5e3a..5c5c9a9460 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -43,6 +43,7 @@ The global configuration looks like this: 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 +53,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 + take-incremented-version: TakeAlwaysIncrementedVersion label: alpha increment: Minor prevent-increment-of-merged-branch-version: 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,11 +82,14 @@ 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 + take-incremented-version: TakeAlwaysIncrementedVersion label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -90,12 +100,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 +117,7 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 pull-request: mode: ContinuousDelivery @@ -120,9 +132,10 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 hotfix: - mode: ContinuousDelivery + mode: ManualDeployment label: beta increment: Inherit regex: ^hotfix(es)?[/-] @@ -131,6 +144,8 @@ branches: - main - support - hotfix + is-source-branch-for: [] + is-release-branch: true pre-release-weight: 30000 support: label: '' @@ -140,15 +155,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,9 +173,11 @@ branches: - pull-request - hotfix - support + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery +take-incremented-version: TakeTaggedOtherwiseIncrementedVersion label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false @@ -167,6 +185,8 @@ 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 @@ -244,7 +264,11 @@ 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]. + +### take-incremented-version + +This branch related property can be used to control the behavior weither to take the incremented or the tagged version. ### increment diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index 5ec390d2d5..7a4a1d3a4a 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -19,6 +19,7 @@ strategies: - VersionInBranchName branches: develop: + take-incremented-version: TakeAlwaysIncrementedVersion label: alpha increment: Minor prevent-increment-of-merged-branch-version: false @@ -46,6 +47,7 @@ branches: pre-release-weight: 55000 release: mode: ManualDeployment + take-incremented-version: TakeAlwaysIncrementedVersion label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -133,6 +135,7 @@ branches: ignore: sha: [] mode: ContinuousDelivery +take-incremented-version: TakeTaggedOtherwiseIncrementedVersion label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false diff --git a/src/GitVersion.Configuration/BranchConfiguration.cs b/src/GitVersion.Configuration/BranchConfiguration.cs index 972c1e43b7..f5ea16d7a4 100644 --- a/src/GitVersion.Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Configuration/BranchConfiguration.cs @@ -10,6 +10,10 @@ internal record BranchConfiguration : IBranchConfiguration [JsonPropertyDescription("The deployment mode for this branch. Can be 'ManualDeployment', 'ContinuousDelivery', 'ContinuousDeployment'.")] public DeploymentMode? DeploymentMode { get; internal set; } + [JsonPropertyName("take-incremented-version")] + [JsonPropertyDescription("Option to control which version should be taken for this branch. Can be 'TakeAlwaysBaseVersion', 'TakeTaggedOtherwiseIncrementedVersion', 'TakeAlwaysIncrementedVersion'.")] + public TakeIncrementedVersion? TakeIncrementedVersion { get; internal set; } + [JsonPropertyName("label")] [JsonPropertyDescription("The label to use for this branch. Use the value {BranchName} or similar as a placeholder to insert a named capture group from RegularExpression (fx. the branch name).")] public string? Label { get; internal set; } @@ -86,6 +90,7 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration) { Increment = Increment == IncrementStrategy.Inherit ? configuration.Increment : Increment, DeploymentMode = DeploymentMode ?? configuration.DeploymentMode, + TakeIncrementedVersion = TakeIncrementedVersion ?? configuration.TakeIncrementedVersion, Label = Label ?? configuration.Label, PreventIncrementOfMergedBranchVersion = PreventIncrementOfMergedBranchVersion ?? configuration.PreventIncrementOfMergedBranchVersion, diff --git a/src/GitVersion.Configuration/BranchConfigurationBuilder.cs b/src/GitVersion.Configuration/BranchConfigurationBuilder.cs index 1df170ed06..eaa34b8291 100644 --- a/src/GitVersion.Configuration/BranchConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/BranchConfigurationBuilder.cs @@ -7,6 +7,7 @@ internal class BranchConfigurationBuilder public static BranchConfigurationBuilder New => new(); private DeploymentMode? deploymentMode; + private TakeIncrementedVersion? takeIncrementedVersion; private string? label; private IncrementStrategy increment; private bool? preventIncrementOfMergedBranchVersion; @@ -32,6 +33,12 @@ public virtual BranchConfigurationBuilder WithDeploymentMode(DeploymentMode? val return this; } + public virtual BranchConfigurationBuilder WithTakeIncrementedVersion(TakeIncrementedVersion? value) + { + this.takeIncrementedVersion = value; + return this; + } + public virtual BranchConfigurationBuilder WithLabel(string? value) { this.label = value; @@ -131,6 +138,7 @@ public virtual BranchConfigurationBuilder WithPreReleaseWeight(int? value) public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration value) { WithDeploymentMode(value.DeploymentMode); + WithTakeIncrementedVersion(value.TakeIncrementedVersion); WithLabel(value.Label); WithIncrement(value.Increment); WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); @@ -151,6 +159,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration public IBranchConfiguration Build() => new BranchConfiguration { DeploymentMode = deploymentMode, + TakeIncrementedVersion = takeIncrementedVersion, Label = label, Increment = increment, RegularExpression = regularExpression, diff --git a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs index 5f14b2a5f8..b330c7afa2 100644 --- a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs @@ -29,6 +29,7 @@ internal abstract class ConfigurationBuilderBase : IConfi private readonly List> overrides = new(); private readonly Dictionary branchConfigurationBuilders = new(); private DeploymentMode? versioningMode; + private TakeIncrementedVersion? takeIncrementedVersion; private string? label; private IncrementStrategy increment = IncrementStrategy.Inherit; private bool? preventIncrementOfMergedBranchVersion; @@ -237,6 +238,12 @@ public virtual TConfigurationBuilder WithDeploymentMode(DeploymentMode? value) return (TConfigurationBuilder)this; } + public virtual TConfigurationBuilder WithTakeIncrementedVersion(TakeIncrementedVersion? value) + { + this.takeIncrementedVersion = value; + return (TConfigurationBuilder)this; + } + public virtual TConfigurationBuilder WithLabel(string? value) { this.label = value; @@ -335,6 +342,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration WithBranch(name).WithConfiguration(branchConfiguration); } WithDeploymentMode(value.DeploymentMode); + WithTakeIncrementedVersion(value.TakeIncrementedVersion); WithLabel(value.Label); WithIncrement(value.Increment); WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); @@ -393,6 +401,7 @@ public virtual IGitVersionConfiguration Build() Branches = branches, MergeMessageFormats = this.mergeMessageFormats, DeploymentMode = this.versioningMode, + TakeIncrementedVersion = this.takeIncrementedVersion, Label = this.label, Increment = this.increment, RegularExpression = this.regularExpression, diff --git a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs index 8eb9ad2080..7cdefdef97 100644 --- a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs @@ -24,6 +24,7 @@ private GitFlowConfigurationBuilder() TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight, UpdateBuildNumber = ConfigurationConstants.DefaultUpdateBuildNumber, DeploymentMode = DeploymentMode.ContinuousDelivery, + TakeIncrementedVersion = TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion, RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit, @@ -39,6 +40,7 @@ private GitFlowConfigurationBuilder() WithBranch(DevelopBranch.Name).WithConfiguration(new BranchConfiguration { Increment = IncrementStrategy.Minor, + TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion, RegularExpression = DevelopBranch.RegexPattern, SourceBranches = [], Label = "alpha", @@ -71,6 +73,7 @@ private GitFlowConfigurationBuilder() WithBranch(ReleaseBranch.Name).WithConfiguration(new BranchConfiguration { Increment = IncrementStrategy.None, + TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion, DeploymentMode = DeploymentMode.ManualDeployment, RegularExpression = ReleaseBranch.RegexPattern, SourceBranches = diff --git a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs index 64473f276b..b5cb3850f7 100644 --- a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs @@ -27,6 +27,7 @@ private GitHubFlowConfigurationBuilder() RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit, + TakeIncrementedVersion = TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion, CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, PreventIncrementOfMergedBranchVersion = false, TrackMergeTarget = false, @@ -53,6 +54,7 @@ private GitHubFlowConfigurationBuilder() WithBranch(ReleaseBranch.Name).WithConfiguration(new BranchConfiguration { Increment = IncrementStrategy.None, + TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion, RegularExpression = ReleaseBranch.RegexPattern, DeploymentMode = DeploymentMode.ManualDeployment, SourceBranches = diff --git a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml index c3a60438a3..7a4a1d3a4a 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml @@ -19,12 +19,14 @@ strategies: - VersionInBranchName branches: develop: + take-incremented-version: TakeAlwaysIncrementedVersion label: alpha increment: Minor prevent-increment-of-merged-branch-version: 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,12 +40,14 @@ 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 + take-incremented-version: TakeAlwaysIncrementedVersion label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -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,6 +90,7 @@ branches: - feature - support - hotfix + is-source-branch-for: [] pre-release-weight: 30000 hotfix: mode: ManualDeployment @@ -95,6 +102,7 @@ branches: - main - support - hotfix + is-source-branch-for: [] is-release-branch: true pre-release-weight: 30000 support: @@ -105,6 +113,7 @@ branches: regex: ^support[/-] source-branches: - main + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -122,9 +131,11 @@ branches: - pull-request - hotfix - support + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery +take-incremented-version: TakeTaggedOtherwiseIncrementedVersion label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false @@ -132,6 +143,8 @@ 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..424c76ae98 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml @@ -26,12 +26,14 @@ branches: 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 + take-incremented-version: TakeAlwaysIncrementedVersion label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -40,6 +42,7 @@ branches: 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,9 +80,11 @@ branches: - release - feature - pull-request + is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery +take-incremented-version: TakeTaggedOtherwiseIncrementedVersion label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false @@ -85,6 +92,8 @@ 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..24fdd0408c 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml @@ -28,12 +28,14 @@ branches: is-main-branch: true pre-release-weight: 55000 feature: + take-incremented-version: TakeAlwaysIncrementedVersion increment: Minor regex: ^features?[/-](?.+) source-branches: - main pre-release-weight: 30000 hotfix: + take-incremented-version: TakeAlwaysIncrementedVersion increment: Patch regex: ^hotfix(es)?[/-](?.+) source-branches: @@ -60,6 +62,7 @@ branches: ignore: sha: [] mode: ManualDeployment +take-incremented-version: TakeTaggedOtherwiseIncrementedVersion label: '{BranchName}' increment: Inherit prevent-increment-of-merged-branch-version: false diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs index 0bda894402..eb0c968acd 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] @@ -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..8b920fc85e 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs @@ -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(); @@ -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/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..4bc6e6b24c 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs @@ -179,7 +179,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(); 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/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index 6482eb5b16..cf3fcc3dc7 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -19,7 +19,10 @@ 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 (!branchConfiguration.TakeIncrementedVersion.HasValue) + throw new("Configuration value for 'Tak incremented version' 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)"); @@ -39,6 +42,7 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon AssemblyVersioningFormat = configuration.AssemblyVersioningFormat; AssemblyFileVersioningFormat = configuration.AssemblyFileVersioningFormat; DeploymentMode = branchConfiguration.DeploymentMode.Value; + TakeIncrementedVersion = branchConfiguration.TakeIncrementedVersion.Value; TagPrefix = configuration.TagPrefix; VersionInBranchRegex = configuration.VersionInBranchRegex; Label = branchConfiguration.Label; @@ -129,6 +133,7 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche public bool IsReleaseBranch { get; } public bool IsMainBranch { get; } public DeploymentMode DeploymentMode { get; } + public TakeIncrementedVersion TakeIncrementedVersion { get; } public AssemblyVersioningScheme AssemblyVersioningScheme { get; } public AssemblyFileVersioningScheme AssemblyFileVersioningScheme { get; } public string? AssemblyInformationalFormat { get; } diff --git a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs index 1da6adfe70..84f91e302a 100644 --- a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs @@ -7,6 +7,8 @@ public interface IBranchConfiguration { DeploymentMode? DeploymentMode { get; } + TakeIncrementedVersion? TakeIncrementedVersion { get; } + string? Label { get; } IncrementStrategy Increment { get; } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index ae6b261883..cdbc0868ec 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -139,6 +139,7 @@ GitVersion.Configuration.EffectiveConfiguration.PatchVersionBumpMessage.get -> s GitVersion.Configuration.EffectiveConfiguration.PreReleaseWeight.get -> int GitVersion.Configuration.EffectiveConfiguration.PreventIncrementOfMergedBranchVersion.get -> bool GitVersion.Configuration.EffectiveConfiguration.SemanticVersionFormat.get -> GitVersion.SemanticVersionFormat +GitVersion.Configuration.EffectiveConfiguration.TakeIncrementedVersion.get -> GitVersion.VersionCalculation.TakeIncrementedVersion GitVersion.Configuration.EffectiveConfiguration.TrackMergeMessage.get -> bool GitVersion.Configuration.EffectiveConfiguration.TrackMergeTarget.get -> bool GitVersion.Configuration.EffectiveConfiguration.TracksReleaseBranches.get -> bool @@ -162,6 +163,7 @@ GitVersion.Configuration.IBranchConfiguration.PreReleaseWeight.get -> int? GitVersion.Configuration.IBranchConfiguration.PreventIncrementOfMergedBranchVersion.get -> bool? GitVersion.Configuration.IBranchConfiguration.RegularExpression.get -> string? GitVersion.Configuration.IBranchConfiguration.SourceBranches.get -> System.Collections.Generic.IReadOnlyCollection! +GitVersion.Configuration.IBranchConfiguration.TakeIncrementedVersion.get -> GitVersion.VersionCalculation.TakeIncrementedVersion? GitVersion.Configuration.IBranchConfiguration.TrackMergeMessage.get -> bool? GitVersion.Configuration.IBranchConfiguration.TrackMergeTarget.get -> bool? GitVersion.Configuration.IBranchConfiguration.TracksReleaseBranches.get -> bool? @@ -713,6 +715,10 @@ GitVersion.VersionCalculation.NextVersion.Configuration.get -> GitVersion.Config GitVersion.VersionCalculation.NextVersion.Equals(GitVersion.VersionCalculation.NextVersion? other) -> bool GitVersion.VersionCalculation.NextVersion.IncrementedVersion.get -> GitVersion.SemanticVersion! GitVersion.VersionCalculation.NextVersion.NextVersion(GitVersion.SemanticVersion! incrementedVersion, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveBranchConfiguration! configuration) -> void +GitVersion.VersionCalculation.TakeIncrementedVersion +GitVersion.VersionCalculation.TakeIncrementedVersion.TakeAlwaysBaseVersion = 0 -> GitVersion.VersionCalculation.TakeIncrementedVersion +GitVersion.VersionCalculation.TakeIncrementedVersion.TakeAlwaysIncrementedVersion = 2 -> GitVersion.VersionCalculation.TakeIncrementedVersion +GitVersion.VersionCalculation.TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion = 1 -> GitVersion.VersionCalculation.TakeIncrementedVersion GitVersion.VersionCalculation.VersionCalculationModule GitVersion.VersionCalculation.VersionCalculationModule.RegisterTypes(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void GitVersion.VersionCalculation.VersionCalculationModule.VersionCalculationModule() -> void diff --git a/src/GitVersion.Core/VersionCalculation/IncrementedVersionMode.cs b/src/GitVersion.Core/VersionCalculation/IncrementedVersionMode.cs new file mode 100644 index 0000000000..0aea148ba3 --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/IncrementedVersionMode.cs @@ -0,0 +1,8 @@ +namespace GitVersion.VersionCalculation; + +public enum TakeIncrementedVersion +{ + TakeAlwaysBaseVersion, + TakeTaggedOtherwiseIncrementedVersion, + TakeAlwaysIncrementedVersion +} diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs index a493c538ed..6592f01527 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs @@ -5,7 +5,7 @@ namespace GitVersion.VersionCalculation; internal sealed class ContinuousDeliveryVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator { public SemanticVersion Calculate(NextVersion nextVersion) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs index bd8c4b5f2f..98f70c509e 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs @@ -5,7 +5,7 @@ namespace GitVersion.VersionCalculation; internal sealed class ContinuousDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator { public SemanticVersion Calculate(NextVersion nextVersion) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs index d6d7d9a197..bccbcaa873 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs @@ -4,7 +4,7 @@ namespace GitVersion.VersionCalculation; internal sealed class ManualDeploymentVersionCalculator(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) - : NonTrunkBasedVersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator + : VersionCalculatorBase(log, repositoryStore, versionContext), IVersionModeCalculator { public SemanticVersion Calculate(NextVersion nextVersion) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/VersionCalculatorBase.cs similarity index 85% rename from src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs rename to src/GitVersion.Core/VersionCalculation/VersionCalculators/VersionCalculatorBase.cs index b844c82e64..ad5a37a8cf 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/VersionCalculatorBase.cs @@ -4,7 +4,7 @@ namespace GitVersion.VersionCalculation; -internal abstract class NonTrunkBasedVersionCalculatorBase(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) +internal abstract class VersionCalculatorBase(ILog log, IRepositoryStore repositoryStore, Lazy versionContext) { protected readonly ILog log = log.NotNull(); protected readonly IRepositoryStore repositoryStore = repositoryStore.NotNull(); @@ -16,11 +16,12 @@ 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 + bool shouldTakeIncrementedVersion = Context.CurrentCommit.Sha != nextVersion.BaseVersion.BaseVersionSource?.Sha || Context.CurrentCommitTaggedVersion is null || nextVersion.BaseVersion.SemanticVersion != Context.CurrentCommitTaggedVersion; - // + + return nextVersion.Configuration.TakeIncrementedVersion == TakeIncrementedVersion.TakeAlwaysIncrementedVersion + || nextVersion.Configuration.TakeIncrementedVersion == TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion && shouldTakeIncrementedVersion; } protected SemanticVersion CalculateIncrementedVersion(NextVersion nextVersion)