diff --git a/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt b/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt index 4867b41f53..71bbab7634 100644 --- a/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt +++ b/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt @@ -5,3 +5,4 @@ semantic-version-format: Strict branches: {} ignore: sha: [] +increment: None diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs index e474adc92b..2a0ded56f9 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs @@ -443,11 +443,11 @@ public void VerifyIncrementConfigIsHonoured() .WithIncrement(IncrementStrategy.Minor) .WithBranch("main", builder => builder .WithVersioningMode(VersioningMode.Mainline) - .WithIncrement(null) + .WithIncrement(IncrementStrategy.Inherit) ) .WithBranch("feature", builder => builder .WithVersioningMode(VersioningMode.Mainline) - .WithIncrement(null) + .WithIncrement(IncrementStrategy.Inherit) ) .Build(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs index c3102ca145..c29ac66e85 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs @@ -52,7 +52,7 @@ public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin() } [Test] - public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote() + public void TakesVersionFromNameOfRemoteReleaseBranchInCustom() { using var fixture = new RemoteRepositoryFixture(); fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", "upstream"); @@ -62,6 +62,6 @@ public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote() fixture.LocalRepositoryFixture.Checkout("upstream/release/2.0.0"); - fixture.LocalRepositoryFixture.AssertFullSemver("0.0.0-beta.1+6"); + fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1"); } } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs index eafcb511fc..370ed43dc7 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs @@ -200,28 +200,7 @@ public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementS } [Test] - public void When_getting_configurations_of_an_orphaned_branch_Given_fallback_configuaration_without_increment_Then_result_should_be_empty() - { - // Arrange - var branchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New - .WithIncrement(null) - .WithBranch("develop", builder => builder.WithIncrement(IncrementStrategy.Inherit)) - .Build(); - var repositoryStoreMock = Substitute.For(); - repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); - - var unitUnderTest = new EffectiveBranchConfigurationFinder(Substitute.For(), repositoryStoreMock); - - // Act - var actual = unitUnderTest.GetConfigurations(branchMock, configuration).ToArray(); - - // Assert - actual.ShouldBeEmpty(); - } - - [Test] - public void When_getting_configurations_of_an_orphaned_branch_Given_fallback_configuration_with_increment_inherit_Then_result_should_have_increment_none() + public void When_getting_configurations_of_an_orphaned_branch_Given_fallback_configuration_with_increment_inherit_Then_result_should_be_empty() { // Arrange var branchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); @@ -238,9 +217,7 @@ public void When_getting_configurations_of_an_orphaned_branch_Given_fallback_con var actual = unitUnderTest.GetConfigurations(branchMock, configuration).ToArray(); // Assert - actual.ShouldHaveSingleItem(); - actual[0].Branch.ShouldBe(branchMock); - actual[0].Value.Increment.ShouldBe(IncrementStrategy.None); + actual.ShouldBeEmpty(); } [TestCase(IncrementStrategy.None)] @@ -271,12 +248,13 @@ public void When_getting_configurations_of_an_orphaned_branch_Given_fallback_con } [Test] - public void When_getting_configurations_of_an_unknown_branch_Given_fallback_configuaration_without_increment_and_unknown_configuration_with_increment_inherit_Then_result_should_be_empty() + public void When_getting_configurations_of_an_unknown_branch_Given_fallback_and_unknown_configuration_with_increment_inherit_Then_result_should_be_empty() { // Arrange var branchMock = GitToolsTestingExtensions.CreateMockBranch("unknown", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New - .WithIncrement(null) + .WithIncrement(IncrementStrategy.Inherit) + .WithBranch("unknown", builder => builder.WithIncrement(IncrementStrategy.Inherit)) .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); @@ -301,6 +279,7 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf var branchMock = GitToolsTestingExtensions.CreateMockBranch("unknown", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New .WithIncrement(fallbackIncrement) + .WithBranch("unknown", builder => builder.WithIncrement(IncrementStrategy.Inherit)) .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); @@ -318,13 +297,13 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf [Theory] public void When_getting_configurations_of_an_unknown_branch_Given_fallback_configuaration_with_increment_and_develop_branch_with_increment_Then_result_should_have_develop_increment( - IncrementStrategy fallbackIncrement, IncrementStrategy developBranchIncrement) + IncrementStrategy fallbackIncrement, IncrementStrategy developIncrement) { // Arrange var unknownBranchMock = GitToolsTestingExtensions.CreateMockBranch("unknown", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New .WithIncrement(fallbackIncrement) - .WithBranch("develop", builder => builder.WithIncrement(developBranchIncrement)) + .WithBranch("develop", builder => builder.WithIncrement(developIncrement)) .Build(); var repositoryStoreMock = Substitute.For(); var developBranchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); @@ -336,22 +315,24 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf var actual = unitUnderTest.GetConfigurations(unknownBranchMock, configuration).ToArray(); // Assert - actual.ShouldHaveSingleItem(); - actual[0].Branch.ShouldBe(developBranchMock); - - if (developBranchIncrement == IncrementStrategy.Inherit) + if (fallbackIncrement == IncrementStrategy.Inherit && developIncrement == IncrementStrategy.Inherit) { - if (fallbackIncrement == IncrementStrategy.Inherit) - { - fallbackIncrement = IncrementStrategy.None; - } - actual[0].Value.Increment.ShouldBe(fallbackIncrement); + actual.ShouldBeEmpty(); } else { - actual[0].Value.Increment.ShouldBe(developBranchIncrement); - } + actual.ShouldHaveSingleItem(); + actual[0].Branch.ShouldBe(developBranchMock); + if (developIncrement == IncrementStrategy.Inherit) + { + actual[0].Value.Increment.ShouldBe(fallbackIncrement); + } + else + { + actual[0].Value.Increment.ShouldBe(developIncrement); + } + } } [Theory] @@ -374,14 +355,16 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf var actual = unitUnderTest.GetConfigurations(unknownBranchMock, configuration).ToArray(); // Assert - actual.ShouldHaveSingleItem(); - actual[0].Branch.ShouldBe(developBranchMock); - if (fallbackIncrement == IncrementStrategy.Inherit) { - fallbackIncrement = IncrementStrategy.None; + actual.ShouldBeEmpty(); + } + else + { + actual.ShouldHaveSingleItem(); + actual[0].Branch.ShouldBe(developBranchMock); + actual[0].Value.Increment.ShouldBe(fallbackIncrement); } - actual[0].Value.Increment.ShouldBe(fallbackIncrement); } [TestCase(IncrementStrategy.None)] diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs index 42712fbaee..0994fba50a 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs @@ -60,14 +60,14 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s fixture.Repository.MakeACommit(); fixture.Repository.CreateBranch(branchName); - var configurationBuilder = GitFlowConfigurationBuilder.New - .WithBranch("support", builder => builder.WithIsReleaseBranch(true)); - ConfigurationHelper configurationHelper = new(configurationBuilder.Build()); + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("support", builder => builder.WithIsReleaseBranch(true)) + .Build(); + ConfigurationHelper configurationHelper = new(configuration); var gitRepository = fixture.Repository.ToGitRepository(); var strategy = GetVersionStrategy(fixture.RepositoryPath, gitRepository, branchName, configurationHelper.Dictionary); - var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); diff --git a/src/GitVersion.Core/Configuration/BranchConfiguration.cs b/src/GitVersion.Core/Configuration/BranchConfiguration.cs index 96f63404c6..cf3edfceef 100644 --- a/src/GitVersion.Core/Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Core/Configuration/BranchConfiguration.cs @@ -42,7 +42,7 @@ public BranchConfiguration(BranchConfiguration branchConfiguration) [JsonPropertyName("increment")] [JsonPropertyDescription("The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.")] - public IncrementStrategy? Increment { get; set; } + public IncrementStrategy Increment { get; set; } [JsonPropertyName("prevent-increment-of-merged-branch-version")] [JsonPropertyDescription("Prevent increment of merged branch version.")] @@ -105,7 +105,7 @@ public BranchConfiguration Inherit(BranchConfiguration? parentConfig) var result = new BranchConfiguration(this); - if (result.Increment is null || result.Increment == IncrementStrategy.Inherit) + if (result.Increment == IncrementStrategy.Inherit) result.Increment = parentConfig.Increment; result.VersioningMode ??= parentConfig.VersioningMode; result.Label ??= parentConfig.Label; diff --git a/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs index 9dd2dface8..13d06d3f62 100644 --- a/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs @@ -9,7 +9,7 @@ public class BranchConfigurationBuilder private string name; private VersioningMode? versioningMode; private string? label; - private IncrementStrategy? increment; + private IncrementStrategy increment; private bool? preventIncrementOfMergedBranchVersion; private string? labelNumberPattern; private bool? trackMergeTarget; @@ -45,7 +45,7 @@ public virtual BranchConfigurationBuilder WithLabel(string? value) return this; } - public virtual BranchConfigurationBuilder WithIncrement(IncrementStrategy? value) + public virtual BranchConfigurationBuilder WithIncrement(IncrementStrategy value) { this.increment = value; return this; diff --git a/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs index d4a894f093..e71114ea30 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs @@ -27,7 +27,7 @@ internal abstract class ConfigurationBuilderBase private readonly Dictionary branchConfigurationBuilders = new(); private VersioningMode? versioningMode; private string? label; - private IncrementStrategy? increment; + private IncrementStrategy increment = IncrementStrategy.Inherit; private bool? preventIncrementOfMergedBranchVersion; private string? labelNumberPattern; private bool? trackMergeTarget; @@ -232,7 +232,7 @@ public virtual TConfigurationBuilder WithLabel(string? value) return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithIncrement(IncrementStrategy? value) + public virtual TConfigurationBuilder WithIncrement(IncrementStrategy value) { this.increment = value; return (TConfigurationBuilder)this; diff --git a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs index 2c3fb21fff..13650c0376 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs @@ -7,8 +7,11 @@ namespace GitVersion.Configuration; public static class ConfigurationExtensions { public static EffectiveConfiguration GetEffectiveConfiguration(this GitVersionConfiguration configuration, IBranch branch) + => GetEffectiveConfiguration(configuration, branch.NotNull().Name.WithoutRemote); + + public static EffectiveConfiguration GetEffectiveConfiguration(this GitVersionConfiguration configuration, string branchName) { - var branchConfiguration = configuration.GetBranchConfiguration(branch); + BranchConfiguration branchConfiguration = configuration.GetBranchConfiguration(branchName); return new EffectiveConfiguration(configuration, branchConfiguration); } @@ -25,16 +28,6 @@ public static BranchConfiguration GetBranchConfiguration(this GitVersionConfigur Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit }; - - if (branchConfiguration.Increment == IncrementStrategy.Inherit) - return branchConfiguration; - - var fallbackBranchConfiguration = GetFallbackBranchConfiguration(configuration); - branchConfiguration.Increment ??= fallbackBranchConfiguration.Increment; - if (branchConfiguration.Increment != IncrementStrategy.Inherit) - { - branchConfiguration = branchConfiguration.Inherit(fallbackBranchConfiguration); - } return branchConfiguration; } @@ -61,7 +54,6 @@ private static IEnumerable GetBranchConfigurations(GitVersi public static BranchConfiguration GetFallbackBranchConfiguration(this GitVersionConfiguration configuration) { BranchConfiguration result = new(configuration); - if (result.Increment == IncrementStrategy.Inherit) result.Increment = IncrementStrategy.None; return result; } diff --git a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index 3b6811d773..48ac103a68 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -9,18 +9,18 @@ namespace GitVersion.Configuration; /// public class EffectiveConfiguration { - public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfiguration currentBranchConfig) + public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfiguration branchConfiguration) { configuration.NotNull(); - currentBranchConfig.NotNull(); + branchConfiguration.NotNull(); - var name = currentBranchConfig.Name; + var fallbackBranchConfiguration = configuration.GetFallbackBranchConfiguration(); + branchConfiguration = branchConfiguration.Inherit(fallbackBranchConfiguration); - if (!currentBranchConfig.VersioningMode.HasValue) - throw new Exception($"Configuration value for 'Versioning mode' for branch {name} has no value. (this should not happen, please report an issue)"); + var name = branchConfiguration.Name; - if (!currentBranchConfig.Increment.HasValue) - throw new Exception($"Configuration value for 'Increment' for branch {name} has no value. (this should not happen, please report an issue)"); + if (!branchConfiguration.VersioningMode.HasValue) + throw new Exception($"Configuration value for 'Versioning mode' for branch {name} has no value. (this should not happen, please report an issue)"); if (!configuration.AssemblyVersioningScheme.HasValue) throw new Exception("Configuration value for 'AssemblyVersioningScheme' has no value. (this should not happen, please report an issue)"); @@ -28,7 +28,7 @@ public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfi if (!configuration.AssemblyFileVersioningScheme.HasValue) throw new Exception("Configuration value for 'AssemblyFileVersioningScheme' has no value. (this should not happen, please report an issue)"); - if (!currentBranchConfig.CommitMessageIncrementing.HasValue) + if (!branchConfiguration.CommitMessageIncrementing.HasValue) throw new Exception("Configuration value for 'CommitMessageIncrementing' has no value. (this should not happen, please report an issue)"); if (!configuration.LabelPreReleaseWeight.HasValue) @@ -39,29 +39,29 @@ public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfi AssemblyInformationalFormat = configuration.AssemblyInformationalFormat; AssemblyVersioningFormat = configuration.AssemblyVersioningFormat; AssemblyFileVersioningFormat = configuration.AssemblyFileVersioningFormat; - VersioningMode = currentBranchConfig.VersioningMode.Value; + VersioningMode = branchConfiguration.VersioningMode.Value; LabelPrefix = configuration.LabelPrefix; - Label = currentBranchConfig.Label ?? string.Empty; + Label = branchConfiguration.Label ?? string.Empty; NextVersion = configuration.NextVersion; - Increment = currentBranchConfig.Increment.Value; - BranchPrefixToTrim = currentBranchConfig.Regex; - PreventIncrementOfMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion ?? false; - LabelNumberPattern = currentBranchConfig.LabelNumberPattern; - TrackMergeTarget = currentBranchConfig.TrackMergeTarget ?? false; - TrackMergeMessage = currentBranchConfig.TrackMergeMessage ?? true; + Increment = branchConfiguration.Increment; + BranchPrefixToTrim = branchConfiguration.Regex; + PreventIncrementOfMergedBranchVersion = branchConfiguration.PreventIncrementOfMergedBranchVersion ?? false; + LabelNumberPattern = branchConfiguration.LabelNumberPattern; + TrackMergeTarget = branchConfiguration.TrackMergeTarget ?? false; + TrackMergeMessage = branchConfiguration.TrackMergeMessage ?? true; MajorVersionBumpMessage = configuration.MajorVersionBumpMessage; MinorVersionBumpMessage = configuration.MinorVersionBumpMessage; PatchVersionBumpMessage = configuration.PatchVersionBumpMessage; NoBumpMessage = configuration.NoBumpMessage; - CommitMessageIncrementing = currentBranchConfig.CommitMessageIncrementing.Value; + CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing.Value; VersionFilters = configuration.Ignore.ToFilters(); - TracksReleaseBranches = currentBranchConfig.TracksReleaseBranches ?? false; - IsReleaseBranch = currentBranchConfig.IsReleaseBranch ?? false; - IsMainline = currentBranchConfig.IsMainline ?? false; + TracksReleaseBranches = branchConfiguration.TracksReleaseBranches ?? false; + IsReleaseBranch = branchConfiguration.IsReleaseBranch ?? false; + IsMainline = branchConfiguration.IsMainline ?? false; CommitDateFormat = configuration.CommitDateFormat; UpdateBuildNumber = configuration.UpdateBuildNumber; SemanticVersionFormat = configuration.SemanticVersionFormat; - PreReleaseWeight = currentBranchConfig.PreReleaseWeight ?? 0; + PreReleaseWeight = branchConfiguration.PreReleaseWeight ?? 0; LabelPreReleaseWeight = configuration.LabelPreReleaseWeight.Value; } @@ -174,7 +174,7 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche public bool UpdateBuildNumber { get; } - public SemanticVersionFormat SemanticVersionFormat { get; set; } = SemanticVersionFormat.Strict; + public SemanticVersionFormat SemanticVersionFormat { get; set; } public int PreReleaseWeight { get; } diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index 79911e0105..062cfe1a8f 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -140,20 +140,30 @@ public IEnumerable GetSourceBranches(IBranch branch, GitVersionConfigur public IEnumerable GetSourceBranches(IBranch branch, GitVersionConfiguration configuration, IEnumerable excludedBranches) { + var returnedBranches = new HashSet(); + var referenceLookup = this.repository.Refs.ToLookup(r => r.TargetIdentifier); - var returnedBranches = new HashSet(); - if (referenceLookup.Any()) + foreach (var branchGrouping in FindCommitBranchesWasBranchedFrom(branch, configuration, excludedBranches) + .GroupBy(element => element.Commit, element => element.Branch)) { - foreach (var branchCommit in FindCommitBranchesWasBranchedFrom(branch, configuration, excludedBranches)) + bool referenceMatchFound = false; + var referenceNames = referenceLookup[branchGrouping.Key.Sha].Select(element => element.Name).ToHashSet(); + + foreach (var item in branchGrouping) + { + if (referenceNames.Contains(item.Name)) + { + if (returnedBranches.Add(item)) yield return item; + referenceMatchFound = true; + } + } + + if (!referenceMatchFound) { - foreach (var _ in referenceLookup[branchCommit.Commit.Sha] - .Where(r => r.Name.Friendly == branchCommit.Branch.Name.Friendly)) + foreach (var item in branchGrouping) { - if (returnedBranches.Add(branchCommit.Branch)) - { - yield return branchCommit.Branch; - } + if (returnedBranches.Add(item)) yield return item; } } } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 5b4c010acc..8dc3b064c0 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -94,7 +94,7 @@ GitVersion.Configuration.BranchConfiguration.BranchConfiguration() -> void GitVersion.Configuration.BranchConfiguration.BranchConfiguration(GitVersion.Configuration.BranchConfiguration! branchConfiguration) -> void GitVersion.Configuration.BranchConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode? GitVersion.Configuration.BranchConfiguration.CommitMessageIncrementing.set -> void -GitVersion.Configuration.BranchConfiguration.Increment.get -> GitVersion.IncrementStrategy? +GitVersion.Configuration.BranchConfiguration.Increment.get -> GitVersion.IncrementStrategy GitVersion.Configuration.BranchConfiguration.Increment.set -> void GitVersion.Configuration.BranchConfiguration.Inherit(GitVersion.Configuration.BranchConfiguration? parentConfig) -> GitVersion.Configuration.BranchConfiguration! GitVersion.Configuration.BranchConfiguration.IsMainline.get -> bool? @@ -164,7 +164,7 @@ GitVersion.Configuration.EffectiveConfiguration.AssemblyVersioningScheme.get -> GitVersion.Configuration.EffectiveConfiguration.BranchPrefixToTrim.get -> string? GitVersion.Configuration.EffectiveConfiguration.CommitDateFormat.get -> string? GitVersion.Configuration.EffectiveConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode -GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.Configuration.BranchConfiguration! currentBranchConfig) -> void +GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.Configuration.BranchConfiguration! branchConfiguration) -> void GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Extensions.AssemblyVersioningScheme assemblyVersioningScheme, GitVersion.Extensions.AssemblyFileVersioningScheme assemblyFileVersioningScheme, string? assemblyInformationalFormat, string? assemblyVersioningFormat, string? assemblyFileVersioningFormat, GitVersion.VersionCalculation.VersioningMode versioningMode, string? labelPrefix, string! label, string? nextVersion, GitVersion.IncrementStrategy increment, string? branchPrefixToTrim, 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 isMainline, string? commitDateFormat, bool updateBuildNumber, GitVersion.SemanticVersionFormat semanticVersionFormat, int preReleaseWeight, int labelPreReleaseWeight) -> void GitVersion.Configuration.EffectiveConfiguration.Increment.get -> GitVersion.IncrementStrategy GitVersion.Configuration.EffectiveConfiguration.IsMainline.get -> bool @@ -1063,6 +1063,7 @@ static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(t static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, string! branchName) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetBranchSpecificTag(this GitVersion.Configuration.EffectiveConfiguration! configuration, GitVersion.Logging.ILog! log, string? branchFriendlyName, string? branchNameOverride) -> string! static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> GitVersion.Configuration.EffectiveConfiguration! +static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, string! branchName) -> GitVersion.Configuration.EffectiveConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetFallbackBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetReleaseBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration) -> System.Collections.Generic.List>! static GitVersion.Configuration.ConfigurationExtensions.IsReleaseBranch(this GitVersion.Configuration.GitVersionConfiguration! configuration, string! branchName) -> bool @@ -1187,7 +1188,7 @@ virtual GitVersion.Agents.BuildAgentBase.ShouldCleanUpRemotes() -> bool virtual GitVersion.Agents.BuildAgentBase.WriteIntegration(System.Action! writer, GitVersion.OutputVariables.VersionVariables! variables, bool updateBuildNumber = true) -> void virtual GitVersion.Configuration.BranchConfigurationBuilder.WithCommitMessageIncrementing(GitVersion.VersionCalculation.CommitMessageIncrementMode? value) -> GitVersion.Configuration.BranchConfigurationBuilder! virtual GitVersion.Configuration.BranchConfigurationBuilder.WithConfiguration(GitVersion.Configuration.BranchConfiguration! value) -> GitVersion.Configuration.BranchConfigurationBuilder! -virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIncrement(GitVersion.IncrementStrategy? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIncrement(GitVersion.IncrementStrategy value) -> GitVersion.Configuration.BranchConfigurationBuilder! virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIsMainline(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder! virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIsReleaseBranch(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder! virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIsSourceBranchFor(System.Collections.Generic.IEnumerable? values) -> GitVersion.Configuration.BranchConfigurationBuilder! diff --git a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionInBranchNameVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionInBranchNameVersionStrategy.cs index de9c7147ed..137e7accc2 100644 --- a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionInBranchNameVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionInBranchNameVersionStrategy.cs @@ -18,17 +18,18 @@ public VersionInBranchNameVersionStrategy(IRepositoryStore repositoryStore, Lazy public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { - string nameWithoutOrigin = NameWithoutOrigin(configuration.Branch); - var contextConfiguration = Context.Configuration; - if (contextConfiguration.IsReleaseBranch(nameWithoutOrigin)) + if (!configuration.Value.IsReleaseBranch) yield break; + + var versionInBranch = GetVersionInBranch( + configuration.Branch.Name.Friendly, configuration.Value.LabelPrefix, configuration.Value.SemanticVersionFormat + ); + if (versionInBranch != null) { - var versionInBranch = GetVersionInBranch(configuration.Branch.Name.Friendly, contextConfiguration.LabelPrefix, contextConfiguration.SemanticVersionFormat); - if (versionInBranch != null) - { - var commitBranchWasBranchedFrom = this.repositoryStore.FindCommitBranchWasBranchedFrom(configuration.Branch, contextConfiguration); - var branchNameOverride = Context.CurrentBranch.Name.Friendly.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty); - yield return new BaseVersion("Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom.Commit, branchNameOverride); - } + var commitBranchWasBranchedFrom = this.repositoryStore.FindCommitBranchWasBranchedFrom( + configuration.Branch, Context.Configuration + ); + var branchNameOverride = Context.CurrentBranch.Name.Friendly.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty); + yield return new BaseVersion("Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom.Commit, branchNameOverride); } } @@ -45,8 +46,4 @@ public override IEnumerable GetBaseVersions(EffectiveBranchConfigur return null; } - - private static string NameWithoutOrigin(IBranch branch) => branch.IsRemote && branch.Name.Friendly.StartsWith("origin/") - ? branch.Name.Friendly.Substring("origin/".Length) - : branch.Name.Friendly; } diff --git a/src/GitVersion.Core/VersionCalculation/EffectiveBranchConfigurationFinder.cs b/src/GitVersion.Core/VersionCalculation/EffectiveBranchConfigurationFinder.cs index c528811d83..0ad2e3ebe6 100644 --- a/src/GitVersion.Core/VersionCalculation/EffectiveBranchConfigurationFinder.cs +++ b/src/GitVersion.Core/VersionCalculation/EffectiveBranchConfigurationFinder.cs @@ -45,8 +45,7 @@ private IEnumerable GetEffectiveConfigurationsRecu { // Because the actual branch is marked with the inherit increment strategy we need to either skip the iteration or go further // while inheriting from the fallback branch configuration. This behavior is configurable via the increment settings of the configuration. - var fallbackBranchConfiguration = configuration.GetFallbackBranchConfiguration(); - var skipTraversingOfOrphanedBranches = fallbackBranchConfiguration.Increment == null; + var skipTraversingOfOrphanedBranches = configuration.Increment == IncrementStrategy.Inherit; this.log.Info( $"An orphaned branch '{branch}' has been detected and will be skipped={skipTraversingOfOrphanedBranches}." ); @@ -67,8 +66,6 @@ in GetEffectiveConfigurationsRecursive(sourceBranch, configuration, branchConfig } else { - var fallbackBranchConfiguration = configuration.GetFallbackBranchConfiguration(); - branchConfiguration = branchConfiguration.Inherit(fallbackBranchConfiguration); yield return new(branch, new EffectiveConfiguration(configuration, branchConfiguration)); } } diff --git a/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs index 82941635d3..23a2f91014 100644 --- a/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs @@ -273,12 +273,12 @@ private IBranch FindMainlineBranch(List possibleMainlineBranches, IComm return (null, null); } - private SemanticVersion IncrementForEachCommit(IEnumerable directCommits, SemanticVersion mainlineVersion, INamedReference mainline) + private SemanticVersion IncrementForEachCommit(IEnumerable directCommits, SemanticVersion mainlineVersion, IBranch mainline) { foreach (var directCommit in directCommits) { var directCommitIncrement = this.incrementStrategyFinder.GetIncrementForCommits(context.Configuration, new[] { directCommit }) - ?? FindDefaultIncrementForBranch(context, mainline.Name.Friendly); + ?? FindDefaultIncrementForBranch(context, mainline); mainlineVersion = mainlineVersion.IncrementVersion(directCommitIncrement); this.log.Info($"Direct commit on main {directCommit} incremented base versions {directCommitIncrement}, now {mainlineVersion}"); } @@ -300,29 +300,23 @@ private VersionField TryFindIncrementFromMergeMessage(ICommit? mergeCommit) { var mergeMessage = new MergeMessage(mergeCommit.Message, context.Configuration); var configuration = context.Configuration.GetBranchConfiguration(mergeMessage.MergedBranch); - if (configuration.Increment != null && configuration.Increment != IncrementStrategy.Inherit) + if (configuration.Increment != IncrementStrategy.Inherit) { - return configuration.Increment.Value.ToVersionField(); + return configuration.Increment.ToVersionField(); } } - // Fallback to configuration increment value return FindDefaultIncrementForBranch(context); } - private static VersionField FindDefaultIncrementForBranch(GitVersionContext context, string? branchName = null) - { - var configuration = context.Configuration.GetBranchConfiguration(branchName ?? context.CurrentBranch.Name.WithoutRemote); - if (configuration.Increment != null && configuration.Increment != IncrementStrategy.Inherit) - { - return configuration.Increment.Value.ToVersionField(); - } + private static VersionField FindDefaultIncrementForBranch(GitVersionContext context) + => FindDefaultIncrementForBranch(context, context.CurrentBranch); - // TODO: Hardcoded fallback values are not so good. It might be better to get this information either from the fallback or the unknown - // branch configuration settings I have introduced. We should think about it: This is a cooking machine... the ingredients are coming from the user. ;) - - // Fallback to patch - return VersionField.Patch; + private static VersionField FindDefaultIncrementForBranch(GitVersionContext context, IBranch branch) + { + var increment = context.Configuration.GetEffectiveConfiguration(branch).Increment; + if (increment == IncrementStrategy.Inherit) increment = IncrementStrategy.Patch; + return increment.ToVersionField(); } private static ICommit GetMergedHead(ICommit mergeCommit)