From 3400a4f429b12f587356d59a0b4bfc89ba80a473 Mon Sep 17 00:00:00 2001 From: Hardy Hobeck Date: Wed, 22 Feb 2023 13:54:12 +0100 Subject: [PATCH 1/3] - Integrate the fallback branch configuration with all branch related properties in the root configuration. - Create a new configuration section with name unknown to ensure the unknown branch configuration. - The way how the configuration (file, parameter) will be merged with the build-in gitflow configuration has been changed. --- BREAKING_CHANGES.md | 20 +- docs/input/docs/reference/configuration.md | 152 +++++++-- docs/input/docs/usage/cli/arguments.md | 2 +- .../ArgumentParserTests.cs | 28 +- .../GitVersion.App.Tests.csproj | 2 +- src/GitVersion.App/ArgumentParser.cs | 2 +- src/GitVersion.App/Arguments.cs | 5 +- src/GitVersion.App/GitVersionExecutor.cs | 4 +- .../OverrideConfigurationOptionParser.cs | 54 +-- src/GitVersion.App/PublicAPI.Unshipped.txt | 2 +- ...riteOutEffectiveConfiguration.approved.txt | 35 +- .../ConfigurationProviderTests.cs | 94 ++---- ...itScenarios.CanSetNextVersion.approved.txt | 4 +- .../Core/GitVersionExecutorTests.cs | 10 +- .../Extensions/GitToolsTestingExtensions.cs | 51 ++- .../Helpers/EmptyConfigurationBuilder.cs | 10 - .../Helpers/GitVersionContextBuilder.cs | 13 +- src/GitVersion.Core.Tests/Helpers/TestBase.cs | 6 +- .../Helpers/TestEffectiveConfiguration.cs | 4 +- .../ContinuousDeploymentTestScenarios.cs | 41 ++- ...FeatureBranchFromAReleaseBranchScenario.cs | 2 +- .../IntegrationTests/DevelopScenarios.cs | 94 +++--- .../FeatureBranchScenarios.cs | 182 +++------- .../IntegrationTests/HotfixBranchScenarios.cs | 97 +++--- .../IntegrationTests/IgnoreBeforeScenarios.cs | 1 + .../IntegrationTests/MainScenarios.cs | 65 ++-- .../MainlineDevelopmentMode.cs | 252 +++++++------- .../IntegrationTests/OtherBranchScenarios.cs | 25 +- .../ReleaseBranchScenarios.cs | 99 ++---- .../RepositoryFixtureExtensions.cs | 26 ++ .../VersionBumpingScenarios.cs | 37 +- .../VersionInCurrentBranchNameScenarios.cs | 7 +- .../VersionInMergedBranchNameScenarios.cs | 7 +- .../IntegrationTests/VersionInTagScenarios.cs | 40 +-- ...EffectiveBranchConfigurationFinderTests.cs | 57 ++-- .../NextVersionCalculatorTests.cs | 153 ++++----- ...nfigNextVersionBaseVersionStrategyTests.cs | 34 +- .../MergeMessageBaseVersionStrategyTests.cs | 15 +- ...ionInBranchNameBaseVersionStrategyTests.cs | 12 +- .../VariableProviderTests.cs | 4 +- src/GitVersion.Core/ConfigInfo.cs | 4 +- .../Abstractions/IConfigurationFileLocator.cs | 1 + .../Abstractions/IConfigurationProvider.cs | 2 +- .../Configuration/BranchConfiguration.cs | 71 ++-- .../BranchConfigurationBuilder.cs} | 75 +++-- .../Configuration/ConfigurationBuilder.cs | 317 ------------------ .../ConfigurationBuilderBase.cs} | 269 ++++++++++----- .../Configuration/ConfigurationExtensions.cs | 93 ++--- .../Configuration/ConfigurationFileLocator.cs | 15 + .../Configuration/ConfigurationHelper.cs | 104 ++++++ .../Configuration/ConfigurationProvider.cs | 30 +- .../Configuration/ConfigurationSerializer.cs | 26 +- .../Configuration/EffectiveConfiguration.cs | 11 +- .../EmptyConfigurationBuilder.cs | 10 + .../GitFlowConfigurationBuilder.cs | 77 +++-- .../GitHubFlowConfigurationBuilder.cs | 63 ++-- .../Configuration/GitVersionConfiguration.cs | 33 +- .../Configuration/IgnoreConfiguration.cs | 4 +- .../Configuration/Init/EditConfigStep.cs | 2 +- .../Init/SetConfig/ConfigureBranches.cs | 2 +- .../Core/GitVersionCalculateTool.cs | 2 +- .../Core/GitVersionContextFactory.cs | 3 +- src/GitVersion.Core/PublicAPI.Unshipped.txt | 58 ++-- .../Caching/GitVersionCacheKeyFactory.cs | 14 +- .../Caching/IGitVersionCacheKeyFactory.cs | 4 +- .../NextVersionCalculator.cs | 4 +- .../VersionCalculation/VariableProvider.cs | 2 +- .../GitVersionTaskExecutor.cs | 4 +- .../PublicAPI.Unshipped.txt | 2 +- src/GitVersion.Testing/GitTestExtensions.cs | 2 +- 70 files changed, 1459 insertions(+), 1593 deletions(-) delete mode 100644 src/GitVersion.Core.Tests/Helpers/EmptyConfigurationBuilder.cs create mode 100644 src/GitVersion.Core.Tests/IntegrationTests/RepositoryFixtureExtensions.cs rename src/{GitVersion.Core.Tests/Helpers/TestBranchConfigurationBuilder.cs => GitVersion.Core/Configuration/BranchConfigurationBuilder.cs} (53%) delete mode 100644 src/GitVersion.Core/Configuration/ConfigurationBuilder.cs rename src/{GitVersion.Core.Tests/Helpers/TestConfigurationBuilderBase.cs => GitVersion.Core/Configuration/ConfigurationBuilderBase.cs} (63%) create mode 100644 src/GitVersion.Core/Configuration/ConfigurationHelper.cs create mode 100644 src/GitVersion.Core/Configuration/EmptyConfigurationBuilder.cs rename src/{GitVersion.Core.Tests/Helpers => GitVersion.Core/Configuration}/GitFlowConfigurationBuilder.cs (78%) rename src/{GitVersion.Core.Tests/Helpers => GitVersion.Core/Configuration}/GitHubFlowConfigurationBuilder.cs (74%) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 7fc0ba0728..3adb1c6487 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -6,12 +6,22 @@ * Instead of having a single effective configuration, we now have one effective configuration per branch where the increment strategy is not set to `inherit`. * The new implementation of the branch configuration inheritance affects per default only the pull-requests, hotfix and feature branches. In this case the next version will be generated like the child branch is not existing and the commits have been made on the source branch. * The following example illustrates this behavior. On the feature branch the semantic version `1.1.0-just-a-test.1+2` will now be generated instead of version `1.0.0-just-a-test.1+3` previously: - ``` + ``` * 1f1cfb4 52 minutes ago (HEAD -> feature/just-a-test) - * 1f9654d 54 minutes ago (release/1.1.0) - * be72411 56 minutes ago (develop) - * 14800ff 58 minutes ago (tag: 1.0.0, main) - ``` + * 1f9654d 54 minutes ago (release/1.1.0) + * be72411 56 minutes ago (develop) + * 14800ff 58 minutes ago (tag: 1.0.0, main) + ``` +* A new `unknown` branch magic string has been introduced to give the user the possibility to specify the branch configuration for a branch which is not known. A branch is not known if only the regular expression of the branch configuration with the name `unknown` is matching. Please notice that this branch configuration behaves like any other branch configurations. +* Additional `fallback` branch configuration properties have been introduced at the root to define base properties which will be inherit to the branch configurations. That means if no other branch configuration in the inheritance line defines the given property the fallback property applies. Notice that the inheritance tree can be controlled using the increment strategy property in the branch configuration section. + * The following example illustrates this behavior. The hotfix branch configuration overrides the main branch configuration and the result overrides the fallback branch configuration. + ``` + * 1f1cfb4 52 minutes ago (HEAD -> hotfix/just-a-test) + * 14800ff 58 minutes ago (tag: 1.0.0, main) + ``` +* When overriding the configuration with e.g. GitVersion.yaml the software distinguishes between properties who are not existent and properties who are `null`. This is especially important if the user wants to define branch related configuration which are marked with `increment` strategy `Inherit`. +* Following root configuration properties have been removed: + * continuous-delivery-fallback-tag ## v5.0.0 diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index 9e60cd4411..463a0906c8 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -40,25 +40,134 @@ created. Modify this to suit your needs. The global configuration looks like this: ```yaml -next-version: 1.0 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -assembly-informational-format: '{InformationalVersion}' -mode: ContinuousDelivery -increment: Inherit -continuous-delivery-fallback-label: ci -label-prefix: '[vV]' +label-prefix: '[vV]?' 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)' label-pre-release-weight: 60000 -commit-message-incrementing: Enabled +branches: + develop: + mode: ContinuousDeployment + label: alpha + increment: Minor + prevent-increment-of-merged-branch-version: false + track-merge-target: true + regex: ^dev(elop)?(ment)?$ + source-branches: [] + tracks-release-branches: true + is-release-branch: false + is-mainline: false + pre-release-weight: 0 + main: + label: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + regex: ^master$|^main$ + source-branches: + - develop + - release + tracks-release-branches: false + is-release-branch: false + is-mainline: true + pre-release-weight: 55000 + release: + label: beta + increment: None + prevent-increment-of-merged-branch-version: true + track-merge-target: false + regex: ^releases?[/-] + source-branches: + - develop + - main + - support + - release + tracks-release-branches: false + is-release-branch: true + is-mainline: false + pre-release-weight: 30000 + feature: + mode: ContinuousDelivery + label: '{BranchName}' + increment: Inherit + regex: ^features?[/-] + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + pre-release-weight: 30000 + pull-request: + mode: ContinuousDelivery + label: PullRequest + increment: Inherit + label-number-pattern: '[/-](?\d+)' + regex: ^(pull|pull\-requests|pr)[/-] + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + pre-release-weight: 30000 + hotfix: + mode: ContinuousDelivery + label: beta + increment: Inherit + regex: ^hotfix(es)?[/-] + source-branches: + - release + - main + - support + - hotfix + pre-release-weight: 30000 + support: + label: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + regex: ^support[/-] + source-branches: + - main + tracks-release-branches: false + is-release-branch: false + is-mainline: true + pre-release-weight: 55000 + unknown: + mode: ContinuousDelivery + label: '{BranchName}' + increment: Inherit + regex: .* + source-branches: + - main + - develop + - release + - feature + - pull-request + - hotfix + - support ignore: sha: [] - commits-before: yyyy-MM-ddTHH:mm:ss +commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true +mode: ContinuousDelivery +label: '{BranchName}' +increment: Inherit +prevent-increment-of-merged-branch-version: false +track-merge-target: false +commit-message-incrementing: Enabled +regex: '' +tracks-release-branches: false +is-release-branch: false +is-mainline: false + ``` The details of the available options are as follows: @@ -142,25 +251,6 @@ for [increment](#increment), [prevent-increment-of-merged-branch-version](#prevent-increment-of-merged-branch-version) and [tracks-release-branches](#tracks-release-branches). -### continuous-delivery-fallback-label - -When using `mode: ContinuousDeployment`, the value specified in -`continuous-delivery-fallback-label` will be used as the pre-release label for -branches which do not have one specified. Default set to `ci`. - -Just to clarify: For a build name without `...-ci-` or in other -words without a `PreReleaseTag` (ergo `"PreReleaseTag":""` in GitVersion's JSON output) -at the end you would need to set `continuous-delivery-fallback-label` to an empty -string (`''`): - -```yaml -mode: ContinuousDeployment -continuous-delivery-fallback-label: '' -... -``` - -Doing so can be helpful if you use your `main` branch as a `release` branch. - ### label-prefix A regex which is used to trim Git tags before processing (e.g., v1.0.0). Default @@ -200,7 +290,7 @@ The pre-release weight in case of tagged commits. If the value is not set in the configuration, a default weight of 60000 is used instead. If the `WeightedPreReleaseNumber` [variable][variables] is 0 and this parameter is set, its value is used. This helps if your branching model is GitFlow and the last -release build, which is often tagged, can utilise this parameter to produce a +release build, which is often tagged, can utilize this parameter to produce a monotonically increasing build number. ### commit-message-incrementing @@ -441,7 +531,7 @@ Without this configuration value you would have to do: ```yaml branches: unstable: - regex: ... + regex: feature: source-branches: ['unstable', 'develop', 'feature', 'hotfix', 'support'] release: @@ -539,9 +629,9 @@ is set, it would be added to the `PreReleaseNumber` to get a final `pre-release-weight` will be used in the calculation. Related Issues [1145][1145] and [1366][1366]. -### semver-format +### semantic-version-format -Specifies the semver format that is used when parsing the string. +Specifies the semantic version format that is used when parsing the string. Can be `Strict` - using the [regex](https://regex101.com/r/Ly7O1x/3/) or `Loose` the old way of parsing. The default if not specified is `Strict` Example of invalid `Strict`, but valid `Loose` diff --git a/docs/input/docs/usage/cli/arguments.md b/docs/input/docs/usage/cli/arguments.md index 1f809c3698..1fb995114e 100644 --- a/docs/input/docs/usage/cli/arguments.md +++ b/docs/input/docs/usage/cli/arguments.md @@ -117,7 +117,7 @@ Following options are supported: 5. `assembly-versioning-scheme` 7. `commit-date-format` 8. `commit-message-incrementing` -10. `continuous-delivery-fallback-label` +10. `label` 11. `increment` 13. `major-version-bump-message` 14. `minor-version-bump-message` diff --git a/src/GitVersion.App.Tests/ArgumentParserTests.cs b/src/GitVersion.App.Tests/ArgumentParserTests.cs index eba05104d1..8e048443b5 100644 --- a/src/GitVersion.App.Tests/ArgumentParserTests.cs +++ b/src/GitVersion.App.Tests/ArgumentParserTests.cs @@ -386,30 +386,15 @@ private static IEnumerable OverrideconfigWithInvalidOptionTestData { ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsupported 'key'." }; - yield return new TestCaseData("update-build-number=1") - { - ExpectedResult = "Could not parse /overrideconfig option: update-build-number=1. Ensure that 'value' is 'true' or 'false'." - }; - yield return new TestCaseData("label-pre-release-weight=invalid-value") - { - ExpectedResult = "Could not parse /overrideconfig option: label-pre-release-weight=invalid-value. Ensure that 'value' is valid integer number." - }; - yield return new TestCaseData("assembly-versioning-scheme=WrongEnumValue") - { - ExpectedResult = $"Could not parse /overrideconfig option: assembly-versioning-scheme=WrongEnumValue. Ensure that 'value' is valid for specified 'key' enumeration: {System.Environment.NewLine}" + - $"MajorMinorPatchTag{System.Environment.NewLine}" + - $"MajorMinorPatch{System.Environment.NewLine}" + - $"MajorMinor{System.Environment.NewLine}" + - $"Major{System.Environment.NewLine}" + - $"None{System.Environment.NewLine}" - }; } [TestCaseSource(nameof(OverrideConfigWithSingleOptionTestData))] public void OverrideConfigWithSingleOptions(string options, GitVersionConfiguration expected) { var arguments = this.argumentParser.ParseArguments($"/overrideconfig {options}"); - arguments.OverrideConfig.ShouldBeEquivalentTo(expected); + + ConfigurationHelper configruationHelper = new(arguments.OverrideConfig); + configruationHelper.Configuration.ShouldBeEquivalentTo(expected); } private static IEnumerable OverrideConfigWithSingleOptionTestData() @@ -464,10 +449,10 @@ private static IEnumerable OverrideConfigWithSingleOptionTestData( } ); yield return new TestCaseData( - "continuous-delivery-fallback-label=cd-label", + "label=cd-label", new GitVersionConfiguration { - ContinuousDeploymentFallbackLabel = "cd-label" + Label = "cd-label" } ); yield return new TestCaseData( @@ -546,7 +531,8 @@ private static IEnumerable OverrideConfigWithSingleOptionTestData( public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected) { var arguments = this.argumentParser.ParseArguments(options); - arguments.OverrideConfig.ShouldBeEquivalentTo(expected); + ConfigurationHelper configruationHelper = new(arguments.OverrideConfig); + configruationHelper.Configuration.ShouldBeEquivalentTo(expected); } private static IEnumerable OverrideConfigWithMultipleOptionsTestData() diff --git a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj index b1e66b0d2a..bab87578b7 100644 --- a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj +++ b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj @@ -1,7 +1,7 @@ - + diff --git a/src/GitVersion.App/ArgumentParser.cs b/src/GitVersion.App/ArgumentParser.cs index 5d8fe82ed1..1a9ce81158 100644 --- a/src/GitVersion.App/ArgumentParser.cs +++ b/src/GitVersion.App/ArgumentParser.cs @@ -437,7 +437,7 @@ private static void ParseOverrideConfig(Arguments arguments, IReadOnlyCollection } parser.SetValue(optionKey, keyAndValue[1]); } - arguments.OverrideConfig = parser.GetConfig(); + arguments.OverrideConfig = parser.GetOverrideConfiguration(); } private static void ParseUpdateAssemblyInfo(Arguments arguments, string? value, IReadOnlyCollection? values) diff --git a/src/GitVersion.App/Arguments.cs b/src/GitVersion.App/Arguments.cs index 9c6858ee44..5c082a0ce1 100644 --- a/src/GitVersion.App/Arguments.cs +++ b/src/GitVersion.App/Arguments.cs @@ -1,4 +1,3 @@ -using GitVersion.Configuration; using GitVersion.Logging; namespace GitVersion; @@ -8,7 +7,7 @@ public class Arguments public AuthenticationInfo Authentication = new(); public string? ConfigFile; - public GitVersionConfiguration? OverrideConfig; + public IReadOnlyDictionary OverrideConfig; public bool ShowConfig; public string? TargetPath; @@ -62,7 +61,7 @@ public GitVersionOptions ToOptions() ConfigInfo = { ConfigFile = ConfigFile, - OverrideConfig = OverrideConfig, + OverrideConfiguration = OverrideConfig, ShowConfig = ShowConfig }, diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index b9dd660ec2..ce23c3685c 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -64,9 +64,9 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions) var variables = this.gitVersionCalculateTool.CalculateVersionVariables(); - var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfig); + var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfiguration); - this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber ?? true); + this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber); this.gitVersionOutputTool.UpdateAssemblyInfo(variables); this.gitVersionOutputTool.UpdateWixVersionFile(variables); } diff --git a/src/GitVersion.App/OverrideConfigurationOptionParser.cs b/src/GitVersion.App/OverrideConfigurationOptionParser.cs index 9af1221f18..bdf478fda0 100644 --- a/src/GitVersion.App/OverrideConfigurationOptionParser.cs +++ b/src/GitVersion.App/OverrideConfigurationOptionParser.cs @@ -5,11 +5,11 @@ namespace GitVersion; internal class OverrideConfigurationOptionParser { + private readonly Dictionary overrideConfiguration = new(); + private static readonly Lazy> _lazySupportedProperties = new(GetSupportedProperties, true); - private readonly Lazy lazyConfig = new(); - internal static ILookup SupportedProperties => _lazySupportedProperties.Value; /// @@ -49,53 +49,7 @@ private static bool IsSupportedPropertyType(Type propertyType) || unwrappedType == typeof(bool); } - internal void SetValue(string key, string value) - { - if (!SupportedProperties.Contains(key)) - return; - - var unwrappedText = QuotedStringHelpers.UnquoteText(value); - foreach (var pi in SupportedProperties[key]) - { - Type unwrapped = Nullable.GetUnderlyingType(pi.PropertyType) ?? pi.PropertyType; - - if (unwrapped == typeof(string)) - pi.SetValue(this.lazyConfig.Value, unwrappedText); - else if (unwrapped.IsEnum) - { - try - { - var parsedEnum = Enum.Parse(unwrapped, unwrappedText); - pi.SetValue(this.lazyConfig.Value, parsedEnum); - } - catch (ArgumentException) - { - var sb = new StringBuilder(); - - sb.Append($"Could not parse /overrideconfig option: {key}={value}."); - sb.AppendLine(" Ensure that 'value' is valid for specified 'key' enumeration: "); - foreach (var name in Enum.GetNames(unwrapped)) - sb.AppendLine(name); - - throw new WarningException(sb.ToString()); - } - } - else if (unwrapped == typeof(int)) - { - if (int.TryParse(unwrappedText, out int parsedInt)) - pi.SetValue(this.lazyConfig.Value, parsedInt); - else - throw new WarningException($"Could not parse /overrideconfig option: {key}={value}. Ensure that 'value' is valid integer number."); - } - else if (unwrapped == typeof(bool)) - { - if (bool.TryParse(unwrappedText, out bool parsedBool)) - pi.SetValue(this.lazyConfig.Value, parsedBool); - else - throw new WarningException($"Could not parse /overrideconfig option: {key}={value}. Ensure that 'value' is 'true' or 'false'."); - } - } - } + internal void SetValue(string key, string value) => overrideConfiguration[key] = QuotedStringHelpers.UnquoteText(value); - internal GitVersionConfiguration? GetConfig() => this.lazyConfig.IsValueCreated ? this.lazyConfig.Value : null; + internal IReadOnlyDictionary GetOverrideConfiguration() => this.overrideConfiguration; } diff --git a/src/GitVersion.App/PublicAPI.Unshipped.txt b/src/GitVersion.App/PublicAPI.Unshipped.txt index 4158318636..44d3730030 100644 --- a/src/GitVersion.App/PublicAPI.Unshipped.txt +++ b/src/GitVersion.App/PublicAPI.Unshipped.txt @@ -20,7 +20,7 @@ GitVersion.Arguments.NoFetch -> bool GitVersion.Arguments.NoNormalize -> bool GitVersion.Arguments.Output -> System.Collections.Generic.ISet! GitVersion.Arguments.OutputFile -> string? -GitVersion.Arguments.OverrideConfig -> GitVersion.Configuration.GitVersionConfiguration? +GitVersion.Arguments.OverrideConfig -> System.Collections.Generic.IReadOnlyDictionary! GitVersion.Arguments.ShowConfig -> bool GitVersion.Arguments.ShowVariable -> string? GitVersion.Arguments.TargetBranch -> string? diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index b14a97a3c6..f2df8e2215 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -1,14 +1,15 @@ assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -mode: ContinuousDelivery label-prefix: '[vV]?' -continuous-delivery-fallback-label: ci 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)' label-pre-release-weight: 60000 -commit-message-incrementing: Enabled +commit-date-format: yyyy-MM-dd +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict branches: develop: mode: ContinuousDeployment @@ -23,7 +24,6 @@ branches: is-mainline: false pre-release-weight: 0 main: - mode: ContinuousDelivery label: '' increment: Patch prevent-increment-of-merged-branch-version: true @@ -37,7 +37,6 @@ branches: is-mainline: true pre-release-weight: 55000 release: - mode: ContinuousDelivery label: beta increment: None prevent-increment-of-merged-branch-version: true @@ -91,7 +90,6 @@ branches: - hotfix pre-release-weight: 30000 support: - mode: ContinuousDelivery label: '' increment: Patch prevent-increment-of-merged-branch-version: true @@ -103,9 +101,28 @@ branches: is-release-branch: false is-mainline: true pre-release-weight: 55000 + unknown: + mode: ContinuousDelivery + label: '{BranchName}' + increment: Inherit + regex: .* + source-branches: + - main + - develop + - release + - feature + - pull-request + - hotfix + - support ignore: sha: [] +mode: ContinuousDelivery +label: '{BranchName}' increment: Inherit -commit-date-format: yyyy-MM-dd -merge-message-formats: {} -update-build-number: true +prevent-increment-of-merged-branch-version: false +track-merge-target: false +commit-message-incrementing: Enabled +regex: '' +tracks-release-branches: false +is-release-branch: false +is-mainline: false diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs index d1387a74d3..dd57d7b8e8 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs @@ -4,7 +4,6 @@ using GitVersion.Extensions; using GitVersion.Helpers; using GitVersion.Logging; -using GitVersion.VersionCalculation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using YamlDotNet.Serialization; @@ -52,16 +51,6 @@ public void OverwritesDefaultsWithProvidedConfig() configuration.Branches["develop"].Label.ShouldBe("dev"); } - [Test] - public void AllBranchesModeWhenUsingMainline() - { - const string text = "mode: Mainline"; - SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); - var branches = configuration.Branches.Select(x => x.Value); - branches.All(branch => branch.VersioningMode == VersioningMode.Mainline).ShouldBe(true); - } - [Test] public void CanRemoveLabel() { @@ -155,44 +144,6 @@ public void CanProvideConfigForNewBranch() configuration.Branches["bug"].Label.ShouldBe("bugfix"); } - [Test] - public void MasterConfigReplacedWithMain() - { - const string text = @" -next-version: 2.0.0 -branches: - master: - regex: '^master$|^main$' - label: beta"; - SetupConfigFileContent(text); - - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); - - configuration.Branches[MainBranch].Regex.ShouldBe("^master$|^main$"); - configuration.Branches[MainBranch].Label.ShouldBe("beta"); - } - - [Test] - public void MasterConfigReplacedWithMainInSourceBranches() - { - const string text = @" -next-version: 2.0.0 -branches: - breaking: - regex: breaking[/] - mode: ContinuousDeployment - increment: Major - source-branches: ['master'] - is-release-branch: false"; - SetupConfigFileContent(text); - - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); - - configuration.Branches["breaking"].Regex.ShouldBe("breaking[/]"); - configuration.Branches["breaking"].SourceBranches.ShouldHaveSingleItem(); - configuration.Branches["breaking"].SourceBranches?.ShouldContain(MainBranch); - } - [Test] public void NextVersionCanBeInteger() { @@ -304,6 +255,7 @@ public void VerifyAliases() var configuration = typeof(GitVersionConfiguration); var propertiesMissingAlias = configuration.GetProperties() .Where(p => p.GetCustomAttribute() == null) + .Where(p => p.GetCustomAttribute() == null) .Where(p => p.GetCustomAttribute(typeof(YamlMemberAttribute)) == null) .Select(p => p.Name); @@ -413,25 +365,24 @@ public void ShouldNotOverrideAnythingWhenOverrideConfigIsEmpty() label-prefix: custom-label-prefix-from-yml"; SetupConfigFileContent(text); - var expectedConfig = this.configurationProvider.ProvideInternal(this.repoPath); - var overridenConfig = this.configurationProvider.ProvideInternal(this.repoPath, new GitVersionConfiguration()); + var expectedConfig = GitFlowConfigurationBuilder.New + .WithNextVersion("1.2.3") + .WithLabelPrefix("custom-label-prefix-from-yml") + .Build(); + var overridenConfig = this.configurationProvider.ProvideInternal(this.repoPath); overridenConfig.AssemblyVersioningScheme.ShouldBe(expectedConfig.AssemblyVersioningScheme); overridenConfig.AssemblyFileVersioningScheme.ShouldBe(expectedConfig.AssemblyFileVersioningScheme); overridenConfig.AssemblyInformationalFormat.ShouldBe(expectedConfig.AssemblyInformationalFormat); overridenConfig.AssemblyVersioningFormat.ShouldBe(expectedConfig.AssemblyVersioningFormat); overridenConfig.AssemblyFileVersioningFormat.ShouldBe(expectedConfig.AssemblyFileVersioningFormat); - overridenConfig.VersioningMode.ShouldBe(expectedConfig.VersioningMode); overridenConfig.LabelPrefix.ShouldBe(expectedConfig.LabelPrefix); - overridenConfig.ContinuousDeploymentFallbackLabel.ShouldBe(expectedConfig.ContinuousDeploymentFallbackLabel); overridenConfig.NextVersion.ShouldBe(expectedConfig.NextVersion); overridenConfig.MajorVersionBumpMessage.ShouldBe(expectedConfig.MajorVersionBumpMessage); overridenConfig.MinorVersionBumpMessage.ShouldBe(expectedConfig.MinorVersionBumpMessage); overridenConfig.PatchVersionBumpMessage.ShouldBe(expectedConfig.PatchVersionBumpMessage); overridenConfig.NoBumpMessage.ShouldBe(expectedConfig.NoBumpMessage); overridenConfig.LabelPreReleaseWeight.ShouldBe(expectedConfig.LabelPreReleaseWeight); - overridenConfig.CommitMessageIncrementing.ShouldBe(expectedConfig.CommitMessageIncrementing); - overridenConfig.Increment.ShouldBe(expectedConfig.Increment); overridenConfig.CommitDateFormat.ShouldBe(expectedConfig.CommitDateFormat); overridenConfig.MergeMessageFormats.ShouldBe(expectedConfig.MergeMessageFormats); overridenConfig.UpdateBuildNumber.ShouldBe(expectedConfig.UpdateBuildNumber); @@ -471,7 +422,11 @@ public void ShouldOverrideTagPrefixWithOverrideConfigValue([Values] bool tagPref { var text = tagPrefixSetAtYmlFile ? "label-prefix: custom-label-prefix-from-yml" : ""; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, new GitVersionConfiguration { LabelPrefix = "label-prefix-from-override-configuration" }); + var overrideConfiguration = new Dictionary() + { + { "label-prefix", "label-prefix-from-override-configuration" } + }; + var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe("label-prefix-from-override-configuration"); } @@ -481,7 +436,12 @@ public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig() { const string text = ""; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, new GitVersionConfiguration { LabelPrefix = null }); + var overrideConfiguration = new Dictionary() + { + { "next-version", "1.0.0" } + }; + + var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe(GitVersionConfiguration.DefaultLabelPrefix); } @@ -491,8 +451,26 @@ public void ShouldNotOverrideTagPrefixFromConfigFileWhenNotSetInOverrideConfig() { const string text = "label-prefix: custom-label-prefix-from-yml"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, new GitVersionConfiguration { LabelPrefix = null }); + var overrideConfiguration = new Dictionary() + { + { "next-version", "1.0.0" } + }; + var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe("custom-label-prefix-from-yml"); } + + [Test] + public void ShouldOverrideTagPrefixFromConfigFileWhenSetInOverrideConfig() + { + const string text = "label-prefix: custom-label-prefix-from-yml"; + SetupConfigFileContent(text); + var overrideConfiguration = new Dictionary() + { + { "label-prefix", "custom-label-prefix-from-console" } + }; + var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); + + configuration.LabelPrefix.ShouldBe("custom-label-prefix-from-console"); + } } 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 0368e755e7..4867b41f53 100644 --- a/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt +++ b/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt @@ -1,5 +1,7 @@ next-version: 2.0.0 +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict branches: {} ignore: sha: [] -merge-message-formats: {} diff --git a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs index 4ae330abe0..adf278698e 100644 --- a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs +++ b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs @@ -201,8 +201,14 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn var cacheDirectoryTimestamp = this.fileSystem.GetLastDirectoryWrite(cacheDirectory); - var configuration = new ConfigurationBuilder().Add(new GitVersionConfiguration { LabelPrefix = "prefix" }).Build(); - gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath, ConfigInfo = { OverrideConfig = configuration } }; + var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix("prefix").Build(); + var overrideConfiguration = new ConfigurationHelper(configuration).Dictionary; + + gitVersionOptions = new GitVersionOptions + { + WorkingDirectory = fixture.RepositoryPath, + ConfigInfo = { OverrideConfiguration = overrideConfiguration } + }; gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions); versionVariables = gitVersionCalculator.CalculateVersionVariables(); diff --git a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs index 3e19e55de3..4c719114c6 100644 --- a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs +++ b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs @@ -49,40 +49,45 @@ public static IBranch CreateMockBranch(string name, params ICommit[] commits) public static void DumpGraph(this IRepository repository, Action? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits); - public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? branch = null) + public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null) { repository ??= fixture.Repository; + configuration ??= GitFlowConfigurationBuilder.New.Build(); + Console.WriteLine("---------"); + var overrideConfiguration = new Dictionary(); var options = Options.Create(new GitVersionOptions { WorkingDirectory = repository.Info.WorkingDirectory, - ConfigInfo = { OverrideConfig = configuration }, + ConfigInfo = { OverrideConfiguration = overrideConfiguration }, RepositoryInfo = { - TargetBranch = branch, + TargetBranch = targetBranch, CommitId = commitId }, Settings = { OnlyTrackedBranches = onlyTrackedBranches } }); - var sp = ConfigureServices(services => services.AddSingleton(options)); - - var variableProvider = sp.GetRequiredService(); - var nextVersionCalculator = sp.GetRequiredService(); - var contextOptions = sp.GetRequiredService>(); - - var context = contextOptions.Value; - try { - var nextVersion = nextVersionCalculator.FindVersion(); - var variables = variableProvider.GetVariablesFor(nextVersion.IncrementedVersion, nextVersion.Configuration, context.IsCurrentCommitTagged); + var configurationProviderMock = Substitute.For(); + configurationProviderMock.Provide(overrideConfiguration).Returns(configuration); + var sp = ConfigureServices(services => + { + services.AddSingleton(options); + services.AddSingleton(configurationProviderMock); + }); + var variableProvider = sp.GetRequiredService(); + var nextVersionCalculator = sp.GetRequiredService(); + var contextOptions = sp.GetRequiredService>(); + + var context = contextOptions.Value; - return variables; + var nextVersion = nextVersionCalculator.FindVersion(); + return variableProvider.GetVariablesFor(nextVersion.IncrementedVersion, nextVersion.Configuration, context.IsCurrentCommitTagged); } catch (Exception) { - Console.WriteLine("Test failing, dumping repository graph"); repository.DumpGraph(); throw; } @@ -99,21 +104,13 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null) { - Console.WriteLine("---------"); + repository ??= fixture.Repository; - try - { - var variables = fixture.GetVersion(configuration, repository, commitId, onlyTrackedBranches, targetBranch); - variables.FullSemVer.ShouldBe(fullSemver); - } - catch (Exception) - { - (repository ?? fixture.Repository).DumpGraph(); - throw; - } + var variables = GetVersion(fixture, configuration, repository, commitId, onlyTrackedBranches, targetBranch); + variables.FullSemVer.ShouldBe(fullSemver); if (commitId == null) { - fixture.SequenceDiagram.NoteOver(fullSemver, fixture.Repository.Head.FriendlyName, color: "#D3D3D3"); + fixture.SequenceDiagram.NoteOver(fullSemver, repository.Head.FriendlyName, color: "#D3D3D3"); } } diff --git a/src/GitVersion.Core.Tests/Helpers/EmptyConfigurationBuilder.cs b/src/GitVersion.Core.Tests/Helpers/EmptyConfigurationBuilder.cs deleted file mode 100644 index 850cf36a63..0000000000 --- a/src/GitVersion.Core.Tests/Helpers/EmptyConfigurationBuilder.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace GitVersion.Core.Tests.Helpers; - -internal sealed class EmptyConfigurationBuilder : TestConfigurationBuilderBase -{ - public static EmptyConfigurationBuilder New => new(); - - private EmptyConfigurationBuilder() - { - } -} diff --git a/src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs b/src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs index cb4f4f3a2c..e1a3996f84 100644 --- a/src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs +++ b/src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs @@ -1,4 +1,3 @@ -using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; using GitVersion.Extensions; using Microsoft.Extensions.DependencyInjection; @@ -9,7 +8,7 @@ namespace GitVersion.Core.Tests; public class GitVersionContextBuilder { private IGitRepository? repository; - private GitVersionConfiguration? configuration; + private IReadOnlyDictionary? overrideConfiguration; public IServiceProvider? ServicesProvider; private Action? overrideServices; @@ -19,9 +18,9 @@ public GitVersionContextBuilder WithRepository(IGitRepository gitRepository) return this; } - public GitVersionContextBuilder WithConfig(GitVersionConfiguration configurationInfo) + public GitVersionContextBuilder WithOverrideConfiguration(IReadOnlyDictionary? value) { - this.configuration = configurationInfo; + this.overrideConfiguration = value; return this; } @@ -57,14 +56,10 @@ public void Build() { var repo = this.repository ?? CreateRepository(); - var configurationInfo = new ConfigurationBuilder() - .Add(this.configuration ?? new GitVersionConfiguration()) - .Build(); - var options = Options.Create(new GitVersionOptions { WorkingDirectory = new EmptyRepositoryFixture().RepositoryPath, - ConfigInfo = { OverrideConfig = configurationInfo } + ConfigInfo = { OverrideConfiguration = this.overrideConfiguration } }); this.ServicesProvider = ConfigureServices(services => diff --git a/src/GitVersion.Core.Tests/Helpers/TestBase.cs b/src/GitVersion.Core.Tests/Helpers/TestBase.cs index 321dc69dde..156e151a03 100644 --- a/src/GitVersion.Core.Tests/Helpers/TestBase.cs +++ b/src/GitVersion.Core.Tests/Helpers/TestBase.cs @@ -1,4 +1,3 @@ -using GitVersion.Configuration; using GitVersion.Extensions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -19,13 +18,12 @@ protected static IServiceProvider ConfigureServices(Action? return services.BuildServiceProvider(); } - protected static IServiceProvider BuildServiceProvider(string workingDirectory, IGitRepository repository, string branch, GitVersionConfiguration? configuration = null) + protected static IServiceProvider BuildServiceProvider(string workingDirectory, IGitRepository repository, string branch, IReadOnlyDictionary? configuration = null) { - configuration ??= new ConfigurationBuilder().Build(); var options = Options.Create(new GitVersionOptions { WorkingDirectory = workingDirectory, - ConfigInfo = { OverrideConfig = configuration }, + ConfigInfo = { OverrideConfiguration = configuration }, RepositoryInfo = { TargetBranch = branch } }); diff --git a/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs b/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs index 5cb30e53bd..96630ef6bc 100644 --- a/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs +++ b/src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs @@ -14,12 +14,11 @@ public TestEffectiveConfiguration( string? assemblyInformationalFormat = null, VersioningMode versioningMode = VersioningMode.ContinuousDelivery, string labelPrefix = GitVersionConfiguration.DefaultLabelPrefix, - string label = "", + string label = "ci", string? nextVersion = null, string branchPrefixToTrim = "", bool preventIncrementOfMergedBranchVersion = false, string? labelNumberPattern = null, - string continuousDeploymentFallbackLabel = "ci", bool trackMergeTarget = false, string? majorMessage = null, string? minorMessage = null, @@ -45,7 +44,6 @@ public TestEffectiveConfiguration( branchPrefixToTrim, preventIncrementOfMergedBranchVersion, labelNumberPattern, - continuousDeploymentFallbackLabel, trackMergeTarget, majorMessage, minorMessage, diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ContinuousDeploymentTestScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/ContinuousDeploymentTestScenarios.cs index 2e420d114d..5b9f250716 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/ContinuousDeploymentTestScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/ContinuousDeploymentTestScenarios.cs @@ -1,4 +1,4 @@ -using GitVersion.Core.Tests.Helpers; +using GitVersion.Configuration; using GitVersion.VersionCalculation; namespace GitVersion.Core.Tests.IntegrationTests; @@ -13,7 +13,10 @@ public void ShouldUseTheFallbackVersionOnMainWhenNoVersionsAreAvailable() var configuration = GitFlowConfigurationBuilder.New .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("main", builder => builder + .WithLabel("ci") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + ) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -31,7 +34,9 @@ public void ShouldUseTheFallbackVersionOnDevelopWhenNoVersionsAreAvailable() { // * a831d61 58 minutes ago (HEAD -> develop) - var configuration = GitFlowConfigurationBuilder.New.WithVersioningMode(VersioningMode.ContinuousDeployment).Build(); + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture("develop"); @@ -49,8 +54,12 @@ public void ShouldUseConfiguredNextVersionOnMainWhenNoHigherVersionsAvailable() // * 8c64db3 58 minutes ago (HEAD -> main) var configuration = GitFlowConfigurationBuilder.New - .WithNextVersion("1.0.0").WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithNextVersion("1.0.0") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithBranch("main", builder => builder + .WithLabel("ci") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + ) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -69,8 +78,9 @@ public void ShouldNotMatterWhenConfiguredNextVersionIsEqualsToTheTaggeVersion() // * 858f71b 58 minutes ago (HEAD -> main, tag: 1.0.0) var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithNextVersion("1.0.0").Build(); + .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -112,7 +122,10 @@ public void ShouldCalculateTheCorrectVersionWhenMergingFromMainToFeatureBranch() var configuration = GitFlowConfigurationBuilder.New .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("main", builder => builder + .WithLabel("ci") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + ) .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) .Build(); @@ -269,7 +282,9 @@ public void ShouldFallbackToTheVersionOnDevelopLikeTheReleaseWasNeverCreatedWhen var configuration = GitFlowConfigurationBuilder.New .WithBranch("main", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment).WithTrackMergeTarget(false) + .WithLabel("ci") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithTrackMergeTarget(false) ) .WithBranch("develop", builder => builder .WithVersioningMode(VersioningMode.ContinuousDeployment).WithTrackMergeTarget(false) @@ -353,13 +368,17 @@ public void ShouldConsiderTheMergeCommitFromMainToDevelopWhenReleaseHasBeenMerge var configuration = GitFlowConfigurationBuilder.New .WithBranch("main", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment).WithTrackMergeTarget(false) + .WithLabel("ci") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithTrackMergeTarget(false) ) .WithBranch("develop", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment).WithTrackMergeTarget(false) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithTrackMergeTarget(false) ) .WithBranch("release", builder => builder - .WithVersioningMode(VersioningMode.ContinuousDeployment).WithTrackMergeTarget(false) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithTrackMergeTarget(false) ) .Build(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs b/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs index ad018e25cb..d64d4ee53e 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs @@ -1,4 +1,4 @@ -using GitVersion.Core.Tests.Helpers; +using GitVersion.Configuration; namespace GitVersion.Core.Tests.IntegrationTests; diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs index 2f1bf22e40..6c107f1cbb 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs @@ -52,20 +52,12 @@ public void WhenDevelopBranchedFromTaggedCommitOnMainVersionDoesNotChange() [Test] public void CanChangeDevelopTagViaConfig() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { - "develop", - new BranchConfiguration - { - Label = "alpha", - SourceBranches = new HashSet() - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("develop", builder => builder + .WithLabel("alpha").WithSourceBranches() + ) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop")); @@ -106,21 +98,21 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMainDoesBumpDevelopV fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); Commands.Checkout(fixture.Repository, "develop"); - fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); + fixture.MergeNoFF("release-2.0.0"); fixture.AssertFullSemver("2.1.0-alpha.2"); } [Test] public void CanHandleContinuousDelivery() { - var configuration = new GitVersionConfiguration - { - Branches = { { "develop", new BranchConfiguration { VersioningMode = VersioningMode.ContinuousDelivery } } } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("develop", builder => builder.WithVersioningMode(VersioningMode.ContinuousDelivery)) + .Build(); + using var fixture = new EmptyRepositoryFixture(); - fixture.Repository.MakeATaggedCommit("1.0.0"); - Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop")); - fixture.Repository.MakeATaggedCommit("1.1.0-alpha7"); + fixture.MakeATaggedCommit("1.0.0"); + fixture.BranchTo("develop"); + fixture.MakeATaggedCommit("1.1.0-alpha7"); fixture.AssertFullSemver("1.1.0-alpha.7", configuration); } @@ -220,10 +212,11 @@ public void TagOnHotfixShouldNotAffectDevelop() [Test] public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("develop", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("release", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -261,10 +254,11 @@ public void CommitsSinceVersionSourceShouldNotGoDownUponGitFlowReleaseFinish() [Test] public void CommitsSinceVersionSourceShouldNotGoDownUponMergingFeatureOnlyToDevelop() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("develop", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("release", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit($"commit in {MainBranch} - 1"); @@ -309,14 +303,14 @@ public void PreviousPreReleaseTagShouldBeRespectedWhenCountingCommits() [Test] public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommitsSinceVersionSourceShouldNotGoDownWhenMergingReleaseToDevelop() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment, - Branches = new Dictionary - { - { "develop", new BranchConfiguration { PreventIncrementOfMergedBranchVersion = false } } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("develop", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithPreventIncrementOfMergedBranchVersion(false) + ) + .WithBranch("release", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string ReleaseBranch = "release/1.1.0"; @@ -356,9 +350,7 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToTrueForDevelopCommit { var configuration = GitFlowConfigurationBuilder.New .WithVersioningMode(VersioningMode.ContinuousDeployment) - .WithBranch("develop", builder => builder - .WithPreventIncrementOfMergedBranchVersion(true) - ) + .WithBranch("develop", builder => builder.WithPreventIncrementOfMergedBranchVersion(true)) .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -397,16 +389,16 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToTrueForDevelopCommit [Test] public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommitsSinceVersionSourceShouldNotGoDownWhenMergingHotfixToDevelop() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment, - Branches = new Dictionary - { - { "develop", new BranchConfiguration { PreventIncrementOfMergedBranchVersion = false } }, - { "hotfix", new BranchConfiguration { PreventIncrementOfMergedBranchVersion = true, Regex = "^(origin/)?hotfix[/-]" } } - - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithBranch("develop", builder => builder + .WithPreventIncrementOfMergedBranchVersion(false) + ) + .WithBranch("hotfix", builder => builder + .WithPreventIncrementOfMergedBranchVersion(true) + .WithRegex("^(origin/)?hotfix[/-]") + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs index 4d5a6e4781..ba27177d19 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -37,22 +37,13 @@ public void ShouldInheritIncrementCorrectlyWithMultiplePossibleParentsAndWeirdly [Test] public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { - "unstable", - new BranchConfiguration - { - Increment = IncrementStrategy.Minor, - Regex = "unstable", - SourceBranches = new HashSet(), - IsSourceBranchFor = new HashSet { "feature" } - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("unstable", builder => builder + .WithIncrement(IncrementStrategy.Minor) + .WithRegex("unstable") + .WithSourceBranches() + .WithIsSourceBranchFor("feature")) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); @@ -166,21 +157,20 @@ public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMa Commands.Checkout(fixture.Repository, branchName); fixture.Repository.Merge(fixture.Repository.Branches["develop"], Generate.SignatureNow()); - var configuration = new GitVersionConfiguration { VersioningMode = VersioningMode.ContinuousDeployment }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); fixture.AssertFullSemver("1.2.0-longrunning.2", configuration); } [Test] public void CanUseBranchNameOffAReleaseBranch() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { "release", new BranchConfiguration { Label = "build" } }, - { "feature", new BranchConfiguration { Label = "useBranchName" } } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("release", builder => builder.WithLabel("build")) + .WithBranch("feature", builder => builder.WithLabel("{BranchName}")) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -198,19 +188,14 @@ public void CanUseBranchNameOffAReleaseBranch() [TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")] public void ShouldUseConfiguredTag(string tag, string featureName, string preReleaseTagName) { - var configuration = new GitVersionConfiguration - { - Branches = - { - { "feature", new BranchConfiguration { Label = tag } } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("feature", builder => builder.WithLabel(tag)) + .Build(); using var fixture = new EmptyRepositoryFixture(); - fixture.Repository.MakeATaggedCommit("1.0.0"); + fixture.MakeATaggedCommit("1.0.0"); var featureBranchName = $"feature/{featureName}"; - fixture.Repository.CreateBranch(featureBranchName); - Commands.Checkout(fixture.Repository, featureBranchName); + fixture.BranchTo(featureBranchName); fixture.Repository.MakeCommits(5); var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5"; @@ -298,19 +283,9 @@ public class WhenMainAsIsDevelop [Test] public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - TracksReleaseBranches = true, - Regex = MainBranch - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithTracksReleaseBranches(true)) + .Build(); using var fixture = new EmptyRepositoryFixture(); // Create release branch @@ -329,19 +304,9 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() [Test] public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - TracksReleaseBranches = true, - Regex = MainBranch - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithTracksReleaseBranches(true)) + .Build(); using var fixture = new EmptyRepositoryFixture(); // Create release branch @@ -408,19 +373,9 @@ public class WhenMainMarkedAsIsDevelop [Test] public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - TracksReleaseBranches = true, - Regex = MainBranch - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithTracksReleaseBranches(true)) + .Build(); using var fixture = new EmptyRepositoryFixture(); // Create release branch @@ -439,19 +394,9 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated() [Test] public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - TracksReleaseBranches = true, - Regex = MainBranch - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithTracksReleaseBranches(true)) + .Build(); using var fixture = new EmptyRepositoryFixture(); // Create release branch @@ -462,7 +407,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() // merge release into main fixture.Checkout(MainBranch); fixture.MergeNoFF("release/1.0.0"); - fixture.AssertFullSemver("1.0.1+2", configuration); + //fixture.AssertFullSemverNew("1.0.1+2", configuration); // create a misnamed feature branch (i.e. it uses the default configuration) from main and verify the version fixture.BranchTo("misnamed"); @@ -474,27 +419,12 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() [Test] public void PickUpVersionFromMainMarkedWithIsTracksReleaseBranches() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDelivery, - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - Label = "pre", - TracksReleaseBranches = true - } - }, - { - "release", new BranchConfiguration - { - IsReleaseBranch = true, - Label = "rc" - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDelivery) + .WithBranch("unknown", builder => builder.WithIncrement(IncrementStrategy.Patch).WithTracksReleaseBranches(true)) + .WithBranch(MainBranch, builder => builder.WithLabel("pre").WithTracksReleaseBranches(true)) + .WithBranch("release", builder => builder.WithLabel("rc").WithTracksReleaseBranches(true)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -518,28 +448,18 @@ public void PickUpVersionFromMainMarkedWithIsTracksReleaseBranches() [Test] public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment, - AssemblyVersioningScheme = AssemblyVersioningScheme.Major, - AssemblyFileVersioningFormat = "{MajorMinorPatch}.{env:WeightedPreReleaseNumber ?? 0}", - CommitMessageIncrementing = CommitMessageIncrementMode.Disabled, - Branches = new Dictionary - { - { - "develop", new BranchConfiguration - { - PreventIncrementOfMergedBranchVersion = true - } - }, - { - "feature", new BranchConfiguration - { - Label = "feat-{BranchName}" - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.Major) + .WithAssemblyFileVersioningFormat("{MajorMinorPatch}.{env:WeightedPreReleaseNumber ?? 0}") + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("develop", builder => builder.WithPreventIncrementOfMergedBranchVersion(true)) + .WithBranch("feature", builder => builder + .WithLabel("feat-{BranchName}") + .WithVersioningMode(VersioningMode.ContinuousDeployment) + ) + .WithCommitMessageIncrementing(CommitMessageIncrementMode.Disabled) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); fixture.BranchTo("develop"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index 3be5cdfbed..f4ec989ba9 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -125,11 +125,14 @@ public void PatchOlderReleaseExample() [Test] public void FeatureOnHotfixFeatureBranchDeleted() { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("hotfix", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string release450 = "release/4.5.0"; @@ -138,36 +141,31 @@ public void FeatureOnHotfixFeatureBranchDeleted() const string tag450 = "4.5.0"; const string featureBranch = "feature/some-bug-fix"; - fixture.Repository.MakeACommit("initial"); - fixture.Repository.CreateBranch("develop"); - Commands.Checkout(fixture.Repository, "develop"); + fixture.MakeACommit("initial"); + fixture.BranchTo("develop"); // create release branch - fixture.Repository.CreateBranch(release450); - Commands.Checkout(fixture.Repository, release450); + fixture.BranchTo(release450); fixture.AssertFullSemver("4.5.0-beta.0", configuration); - fixture.Repository.MakeACommit("blabla"); - Commands.Checkout(fixture.Repository, "develop"); - fixture.Repository.MergeNoFF(release450, Generate.SignatureNow()); - Commands.Checkout(fixture.Repository, MainBranch); - fixture.Repository.MergeNoFF(release450, Generate.SignatureNow()); + fixture.MakeACommit("blabla"); + fixture.Checkout("develop"); + fixture.MergeNoFF(release450); + fixture.Checkout(MainBranch); + fixture.MergeNoFF(release450); // create support branch - fixture.Repository.CreateBranch(support45); - Commands.Checkout(fixture.Repository, support45); - fixture.Repository.ApplyTag(tag450); + fixture.BranchTo(support45); + fixture.ApplyTag(tag450); fixture.AssertFullSemver("4.5.0", configuration); // create hotfix branch - fixture.Repository.CreateBranch(hotfix451); - Commands.Checkout(fixture.Repository, hotfix451); + fixture.BranchTo(hotfix451); // feature branch from hotfix - fixture.Repository.CreateBranch(featureBranch); - Commands.Checkout(fixture.Repository, featureBranch); - fixture.Repository.MakeACommit("blabla"); // commit 1 - Commands.Checkout(fixture.Repository, hotfix451); - fixture.Repository.MergeNoFF(featureBranch, Generate.SignatureNow()); // commit 2 + fixture.BranchTo(featureBranch); + fixture.MakeACommit("blabla"); // commit 1 + fixture.Checkout(hotfix451); + fixture.MergeNoFF(featureBranch); // commit 2 fixture.Repository.Branches.Remove(featureBranch); fixture.AssertFullSemver("4.5.1-beta.2", configuration); } @@ -178,11 +176,14 @@ public void FeatureOnHotfixFeatureBranchDeleted() [Test] public void FeatureOnHotfixFeatureBranchNotDeleted() { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment)) + .WithBranch("hotfix", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string release450 = "release/4.5.0"; @@ -191,37 +192,31 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() const string tag450 = "4.5.0"; const string featureBranch = "feature/some-bug-fix"; - fixture.Repository.MakeACommit("initial"); - fixture.Repository.CreateBranch("develop"); - Commands.Checkout(fixture.Repository, "develop"); + fixture.MakeACommit("initial"); + fixture.BranchTo("develop"); // create release branch - fixture.Repository.CreateBranch(release450); - Commands.Checkout(fixture.Repository, release450); + fixture.BranchTo(release450); fixture.AssertFullSemver("4.5.0-beta.0", configuration); - fixture.Repository.MakeACommit("blabla"); - Commands.Checkout(fixture.Repository, "develop"); - fixture.Repository.MergeNoFF(release450, Generate.SignatureNow()); - Commands.Checkout(fixture.Repository, MainBranch); - fixture.Repository.MergeNoFF(release450, Generate.SignatureNow()); + fixture.MakeACommit("blabla"); + fixture.Checkout("develop"); + fixture.MergeNoFF(release450); + fixture.Checkout(MainBranch); + fixture.MergeNoFF(release450); // create support branch - fixture.Repository.CreateBranch(support45); - Commands.Checkout(fixture.Repository, support45); - fixture.Repository.ApplyTag(tag450); + fixture.BranchTo(support45); + fixture.ApplyTag(tag450); fixture.AssertFullSemver("4.5.0", configuration); // create hotfix branch - fixture.Repository.CreateBranch(hotfix451); - Commands.Checkout(fixture.Repository, hotfix451); + fixture.BranchTo(hotfix451); // feature branch from hotfix - fixture.Repository.CreateBranch(featureBranch); - Commands.Checkout(fixture.Repository, featureBranch); - fixture.Repository.MakeACommit("blabla"); // commit 1 - Commands.Checkout(fixture.Repository, hotfix451); - fixture.Repository.MergeNoFF(featureBranch, Generate.SignatureNow()); // commit 2 + fixture.BranchTo(featureBranch); + fixture.MakeACommit("blabla"); // commit 1 + fixture.Checkout(hotfix451); + fixture.MergeNoFF(featureBranch); // commit 2 fixture.AssertFullSemver("4.5.1-beta.2", configuration); } - } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs index c2dcfe0453..a6cb4200a9 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/IgnoreBeforeScenarios.cs @@ -1,3 +1,4 @@ +using GitVersion.Configuration; using GitVersion.Core.Tests.Helpers; namespace GitVersion.Core.Tests.IntegrationTests; diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs index 152ca39577..2910c0f8f1 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs @@ -11,18 +11,10 @@ public class MainScenarios : TestBase [Test] public void CanHandleContinuousDelivery() { - var configuaration = new GitVersionConfiguration - { - Branches = - { - { - MainBranch, new BranchConfiguration - { - VersioningMode = VersioningMode.ContinuousDelivery - } - } - } - }; + var configuaration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithVersioningMode(VersioningMode.ContinuousDelivery)) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeCommits(2); @@ -32,18 +24,11 @@ public void CanHandleContinuousDelivery() [Test] public void CanHandleContinuousDeployment() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { - MainBranch, new BranchConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder + .WithLabel("ci").WithVersioningMode(VersioningMode.ContinuousDeployment)) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeCommits(2); @@ -98,7 +83,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0 public void GivenARepositoryWithTagAndNextVersionInConfigVersionShouldMatchVersionTxtFile() { const string expectedNextVersion = "1.1.0"; - var configuration = new GitVersionConfiguration { NextVersion = expectedNextVersion }; + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion(expectedNextVersion).Build(); using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); @@ -110,11 +95,13 @@ public void GivenARepositoryWithTagAndNextVersionInConfigVersionShouldMatchVersi [Test] public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShouldBeTag() { + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.1.0").Build(); + using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.AssertFullSemver("1.0.3"); - fixture.AssertFullSemver("1.0.3", new GitVersionConfiguration { NextVersion = "1.1.0" }); + fixture.AssertFullSemver("1.0.3", configuration); } [Test] @@ -128,7 +115,8 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou // I'm not sure if the postfix +1 is correct here... // but the next version configuration property is something for the user to manipulate the resulting version. - fixture.AssertFullSemver("1.1.0+1", new GitVersionConfiguration { NextVersion = "1.1.0" }); + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.1.0").Build(); + fixture.AssertFullSemver("1.1.0+1", configuration); } [Test] @@ -138,7 +126,8 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.AssertFullSemver("1.0.3"); - fixture.AssertFullSemver("1.0.3", new GitVersionConfiguration { NextVersion = "1.0.2" }); + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.2").Build(); + fixture.AssertFullSemver("1.0.3", configuration); } [Test] @@ -149,7 +138,8 @@ public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommitsVersionShou fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.0.4+1"); - fixture.AssertFullSemver("1.0.4+1", new GitVersionConfiguration { NextVersion = "1.0.4" }); + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.4").Build(); + fixture.AssertFullSemver("1.0.4+1", configuration); } [Test] @@ -168,7 +158,7 @@ public void GivenARepositoryWithTagAndNoNextVersionTxtFileAndNoCommitsVersionSho { using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; - fixture.Repository.MakeATaggedCommit(taggedVersion); + fixture.MakeATaggedCommit(taggedVersion); fixture.AssertFullSemver("1.0.3"); } @@ -178,10 +168,11 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigVersionShouldBeTagWith { using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.1.0"; - fixture.Repository.MakeATaggedCommit(taggedVersion); + fixture.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.1.1+5", new GitVersionConfiguration { NextVersion = "1.0.0" }); + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.0").Build(); + fixture.AssertFullSemver("1.1.1+5", configuration); } [Test] @@ -191,7 +182,8 @@ public void GivenARepositoryWithTagAndOldNextVersionConfigAndNoCommitsVersionSho const string taggedVersion = "1.1.0"; fixture.Repository.MakeATaggedCommit(taggedVersion); - fixture.AssertFullSemver("1.1.0", new GitVersionConfiguration { NextVersion = "1.0.0" }); + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.0.0").Build(); + fixture.AssertFullSemver("1.1.0", configuration); } [Test] @@ -202,13 +194,14 @@ public void CanSpecifyTagPrefixes() fixture.Repository.MakeATaggedCommit(taggedVersion); fixture.Repository.MakeCommits(5); - fixture.AssertFullSemver("1.0.4+5", new GitVersionConfiguration { LabelPrefix = "version-" }); + var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix("version-").Build(); + fixture.AssertFullSemver("1.0.4+5", configuration); } [Test] public void CanSpecifyTagPrefixesAsRegex() { - var configuration = new GitVersionConfiguration { LabelPrefix = $"version-|{GitVersionConfiguration.DefaultLabelPrefix}" }; + var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix($"version-|{GitVersionConfiguration.DefaultLabelPrefix}").Build(); using var fixture = new EmptyRepositoryFixture(); var taggedVersion = "v1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); @@ -226,7 +219,7 @@ public void CanSpecifyTagPrefixesAsRegex() [Test] public void AreTagsNotAdheringToTagPrefixIgnored() { - var configuration = new GitVersionConfiguration { LabelPrefix = "" }; + var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix("").Build(); using var fixture = new EmptyRepositoryFixture(); var taggedVersion = "version-1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs index 280844847f..e474adc92b 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs @@ -8,11 +8,18 @@ namespace GitVersion.Core.Tests.IntegrationTests; public class MainlineDevelopmentMode : TestBase { - private readonly GitVersionConfiguration configuration = new() { VersioningMode = VersioningMode.Mainline }; + private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("develop", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("support", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("pull-request", builder => builder.WithVersioningMode(VersioningMode.Mainline)); [Test] public void VerifyNonMainMainlineVersionIdenticalAsMain() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); @@ -21,36 +28,38 @@ public void VerifyNonMainMainlineVersionIdenticalAsMain() fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.0.0", this.configuration); + fixture.AssertFullSemver("1.0.0", configuration); fixture.BranchTo("support/1.0", "support"); - fixture.AssertFullSemver("1.0.0", this.configuration); + fixture.AssertFullSemver("1.0.0", configuration); } [Test] public void MergedFeatureBranchesToMainImpliesRelease() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); fixture.BranchTo("feature/foo", "foo"); fixture.MakeACommit("2"); - fixture.AssertFullSemver("1.0.1-foo.1", this.configuration); + fixture.AssertFullSemver("1.0.1-foo.1", configuration); fixture.MakeACommit("2.1"); - fixture.AssertFullSemver("1.0.1-foo.2", this.configuration); + fixture.AssertFullSemver("1.0.1-foo.2", configuration); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.0.1", this.configuration); + fixture.AssertFullSemver("1.0.1", configuration); fixture.BranchTo("feature/foo2", "foo2"); fixture.MakeACommit("3 +semver: minor"); - fixture.AssertFullSemver("1.1.0-foo2.1", this.configuration); + fixture.AssertFullSemver("1.1.0-foo2.1", configuration); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo2"); - fixture.AssertFullSemver("1.1.0", this.configuration); + fixture.AssertFullSemver("1.1.0", configuration); fixture.BranchTo("feature/foo3", "foo3"); fixture.MakeACommit("4"); @@ -60,93 +69,99 @@ public void MergedFeatureBranchesToMainImpliesRelease() var commit = fixture.Repository.Head.Tip; // Put semver increment in merge message fixture.Repository.Commit(commit.Message + " +semver: minor", commit.Author, commit.Committer, new CommitOptions { AmendPreviousCommit = true }); - fixture.AssertFullSemver("1.2.0", this.configuration); + fixture.AssertFullSemver("1.2.0", configuration); fixture.BranchTo("feature/foo4", "foo4"); fixture.MakeACommit("5 +semver: major"); - fixture.AssertFullSemver("2.0.0-foo4.1", this.configuration); + fixture.AssertFullSemver("2.0.0-foo4.1", configuration); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo4"); - fixture.AssertFullSemver("2.0.0", this.configuration); + fixture.AssertFullSemver("2.0.0", configuration); // We should evaluate any commits not included in merge commit calculations for direct commit/push or squash to merge commits fixture.MakeACommit("6 +semver: major"); - fixture.AssertFullSemver("3.0.0", this.configuration); + fixture.AssertFullSemver("3.0.0", configuration); fixture.MakeACommit("7 +semver: minor"); - fixture.AssertFullSemver("3.1.0", this.configuration); + fixture.AssertFullSemver("3.1.0", configuration); fixture.MakeACommit("8"); - fixture.AssertFullSemver("3.1.1", this.configuration); + fixture.AssertFullSemver("3.1.1", configuration); // Finally verify that the merge commits still function properly fixture.BranchTo("feature/foo5", "foo5"); fixture.MakeACommit("9 +semver: minor"); - fixture.AssertFullSemver("3.2.0-foo5.1", this.configuration); + fixture.AssertFullSemver("3.2.0-foo5.1", configuration); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo5"); - fixture.AssertFullSemver("3.2.0", this.configuration); + fixture.AssertFullSemver("3.2.0", configuration); // One more direct commit for good measure fixture.MakeACommit("10 +semver: minor"); - fixture.AssertFullSemver("3.3.0", this.configuration); + fixture.AssertFullSemver("3.3.0", configuration); // And we can commit without bumping semver fixture.MakeACommit("11 +semver: none"); - fixture.AssertFullSemver("3.3.0", this.configuration); + fixture.AssertFullSemver("3.3.0", configuration); Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } [Test] public void VerifyPullRequestsActLikeContinuousDelivery() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.1", this.configuration); + fixture.AssertFullSemver("1.0.1", configuration); fixture.BranchTo("feature/foo", "foo"); - fixture.AssertFullSemver("1.0.2-foo.0", this.configuration); + fixture.AssertFullSemver("1.0.2-foo.0", configuration); fixture.MakeACommit(); fixture.MakeACommit(); fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, normalise: true, prNumber: 8); - fixture.AssertFullSemver("1.0.2-PullRequest8.3", this.configuration); + fixture.AssertFullSemver("1.0.2-PullRequest8.3", configuration); } [Test] public void SupportBranches() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); fixture.MakeACommit(); // 1.0.1 fixture.MakeACommit(); // 1.0.2 - fixture.AssertFullSemver("1.0.2", this.configuration); + fixture.AssertFullSemver("1.0.2", configuration); fixture.BranchTo("support/1.0", "support10"); - fixture.AssertFullSemver("1.0.2", this.configuration); + fixture.AssertFullSemver("1.0.2", configuration); // Move main on fixture.Checkout(MainBranch); fixture.MakeACommit("+semver: major"); // 2.0.0 (on main) - fixture.AssertFullSemver("2.0.0", this.configuration); + fixture.AssertFullSemver("2.0.0", configuration); // Continue on support/1.0 fixture.Checkout("support/1.0"); fixture.MakeACommit(); // 1.0.3 fixture.MakeACommit(); // 1.0.4 - fixture.AssertFullSemver("1.0.4", this.configuration); + fixture.AssertFullSemver("1.0.4", configuration); fixture.BranchTo("feature/foo", "foo"); - fixture.AssertFullSemver("1.0.5-foo.0", this.configuration); + fixture.AssertFullSemver("1.0.5-foo.0", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.5-foo.1", this.configuration); + fixture.AssertFullSemver("1.0.5-foo.1", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.5-foo.2", this.configuration); + fixture.AssertFullSemver("1.0.5-foo.2", configuration); fixture.Repository.CreatePullRequestRef("feature/foo", "support/1.0", normalise: true, prNumber: 7); - fixture.AssertFullSemver("1.0.5-PullRequest7.3", this.configuration); + fixture.AssertFullSemver("1.0.5-PullRequest7.3", configuration); } [Test] public void VerifyForwardMerge() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); @@ -154,25 +169,27 @@ public void VerifyForwardMerge() fixture.BranchTo("feature/foo", "foo"); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.2-foo.1", this.configuration); + fixture.AssertFullSemver("1.0.2-foo.1", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.2-foo.2", this.configuration); + fixture.AssertFullSemver("1.0.2-foo.2", configuration); fixture.Checkout(MainBranch); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.2", this.configuration); + fixture.AssertFullSemver("1.0.2", configuration); fixture.Checkout("feature/foo"); // This may seem surprising, but this happens because we branched off mainline // and incremented. Mainline has then moved on. We do not follow mainline // in feature branches, you need to merge mainline in to get the mainline version - fixture.AssertFullSemver("1.0.2-foo.2", this.configuration); + fixture.AssertFullSemver("1.0.2-foo.2", configuration); fixture.MergeNoFF(MainBranch); - fixture.AssertFullSemver("1.0.3-foo.3", this.configuration); + fixture.AssertFullSemver("1.0.3-foo.3", configuration); } [Test] public void VerifySupportForwardMerge() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); @@ -184,23 +201,25 @@ public void VerifySupportForwardMerge() fixture.Checkout(MainBranch); fixture.MakeACommit("+semver: minor"); - fixture.AssertFullSemver("1.1.0", this.configuration); + fixture.AssertFullSemver("1.1.0", configuration); fixture.MergeNoFF("support/1.0"); - fixture.AssertFullSemver("1.1.1", this.configuration); + fixture.AssertFullSemver("1.1.1", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.2", this.configuration); + fixture.AssertFullSemver("1.1.2", configuration); fixture.Checkout("support/1.0"); - fixture.AssertFullSemver("1.0.3", this.configuration); + fixture.AssertFullSemver("1.0.3", configuration); fixture.BranchTo("feature/foo", "foo"); fixture.MakeACommit(); fixture.MakeACommit(); - fixture.AssertFullSemver("1.0.4-foo.2", this.configuration); // TODO This probably should be 1.0.5 + fixture.AssertFullSemver("1.0.4-foo.2", configuration); // TODO This probably should be 1.0.5 } [Test] public void VerifyDevelopTracksMainVersion() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); @@ -208,36 +227,38 @@ public void VerifyDevelopTracksMainVersion() // branching increments the version fixture.BranchTo("develop"); - fixture.AssertFullSemver("1.1.0-alpha.0", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.0", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.1", configuration); // merging develop into main increments minor version on main fixture.Checkout(MainBranch); fixture.MergeNoFF("develop"); - fixture.AssertFullSemver("1.1.0", this.configuration); + fixture.AssertFullSemver("1.1.0", configuration); // a commit on develop before the merge still has the same version number fixture.Checkout("develop"); - fixture.AssertFullSemver("1.1.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.1", configuration); // moving on to further work on develop tracks main's version from the merge fixture.MakeACommit(); - fixture.AssertFullSemver("1.2.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.2.0-alpha.1", configuration); // adding a commit to main increments patch fixture.Checkout(MainBranch); fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.1", this.configuration); + fixture.AssertFullSemver("1.1.1", configuration); // adding a commit to main doesn't change develop's version fixture.Checkout("develop"); - fixture.AssertFullSemver("1.2.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.2.0-alpha.1", configuration); } [Test] public void VerifyDevelopFeatureTracksMainVersion() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); fixture.MakeATaggedCommit("1.0.0"); @@ -245,46 +266,48 @@ public void VerifyDevelopFeatureTracksMainVersion() // branching increments the version fixture.BranchTo("develop"); - fixture.AssertFullSemver("1.1.0-alpha.0", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.0", configuration); fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.1", configuration); // merging develop into main increments minor version on main fixture.Checkout(MainBranch); fixture.MergeNoFF("develop"); - fixture.AssertFullSemver("1.1.0", this.configuration); + fixture.AssertFullSemver("1.1.0", configuration); // a commit on develop before the merge still has the same version number fixture.Checkout("develop"); - fixture.AssertFullSemver("1.1.0-alpha.1", this.configuration); + fixture.AssertFullSemver("1.1.0-alpha.1", configuration); // a branch from develop before the merge tracks the pre-merge version from main // (note: the commit on develop looks like a commit to this branch, thus the .1) fixture.BranchTo("feature/foo"); - fixture.AssertFullSemver("1.0.2-foo.1", this.configuration); + fixture.AssertFullSemver("1.0.2-foo.1", configuration); // further work on the branch tracks the merged version from main fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.1-foo.1", this.configuration); + fixture.AssertFullSemver("1.1.1-foo.1", configuration); // adding a commit to main increments patch fixture.Checkout(MainBranch); fixture.MakeACommit(); - fixture.AssertFullSemver("1.1.1", this.configuration); + fixture.AssertFullSemver("1.1.1", configuration); // adding a commit to main doesn't change the feature's version fixture.Checkout("feature/foo"); - fixture.AssertFullSemver("1.1.1-foo.1", this.configuration); + fixture.AssertFullSemver("1.1.1-foo.1", configuration); // merging the feature to develop increments develop fixture.Checkout("develop"); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.2.0-alpha.2", this.configuration); + fixture.AssertFullSemver("1.2.0-alpha.2", configuration); } [Test] public void VerifyMergingMainToFeatureDoesNotCauseBranchCommitsToIncrementVersion() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit($"first in {MainBranch}"); @@ -302,12 +325,14 @@ public void VerifyMergingMainToFeatureDoesNotCauseBranchCommitsToIncrementVersio fixture.MakeATaggedCommit("1.0.0"); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.0.1", this.configuration); + fixture.AssertFullSemver("1.0.1", configuration); } [Test] public void VerifyMergingMainToFeatureDoesNotStopMainCommitsIncrementingVersion() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit($"first in {MainBranch}"); @@ -324,15 +349,17 @@ public void VerifyMergingMainToFeatureDoesNotStopMainCommitsIncrementingVersion( fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.0.2", this.configuration); + fixture.AssertFullSemver("1.0.2", configuration); } [Test] public void VerifyIssue1154CanForwardMergeMainToFeatureBranch() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); - fixture.AssertFullSemver("0.0.1", this.configuration); + fixture.AssertFullSemver("0.0.1", configuration); fixture.BranchTo("feature/branch2"); fixture.BranchTo("feature/branch1"); fixture.MakeACommit(); @@ -340,7 +367,7 @@ public void VerifyIssue1154CanForwardMergeMainToFeatureBranch() fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/branch1"); - fixture.AssertFullSemver("0.0.2", this.configuration); + fixture.AssertFullSemver("0.0.2", configuration); fixture.Checkout("feature/branch2"); fixture.MakeACommit(); @@ -348,12 +375,14 @@ public void VerifyIssue1154CanForwardMergeMainToFeatureBranch() fixture.MakeACommit(); fixture.MergeNoFF(MainBranch); - fixture.AssertFullSemver("0.0.3-branch2.4", this.configuration); + fixture.AssertFullSemver("0.0.3-branch2.4", configuration); } [Test] public void VerifyMergingMainIntoAFeatureBranchWorksWithMultipleBranches() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit($"first in {MainBranch}"); @@ -379,42 +408,48 @@ public void VerifyMergingMainIntoAFeatureBranchWorksWithMultipleBranches() fixture.MergeNoFF("feature/foo"); fixture.MergeNoFF("feature/bar"); - fixture.AssertFullSemver("1.0.2", this.configuration); + fixture.AssertFullSemver("1.0.2", configuration); } [Test] public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionOfMain() { - var currentConfig = new GitVersionConfiguration { VersioningMode = VersioningMode.Mainline, Branches = new Dictionary { { "feature", new BranchConfiguration { VersioningMode = VersioningMode.ContinuousDeployment, Increment = IncrementStrategy.Minor } } } }; + var configuration = GetConfigurationBuilder() + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithIncrement(IncrementStrategy.Minor) + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit($"first in {MainBranch}"); fixture.MakeATaggedCommit("1.0.0"); - fixture.AssertFullSemver("1.0.0", currentConfig); + fixture.AssertFullSemver("1.0.0", configuration); fixture.BranchTo("feature/foo", "foo"); fixture.MakeACommit("first in foo"); fixture.MakeACommit("second in foo"); - fixture.AssertFullSemver("1.1.0-foo.2", currentConfig); + fixture.AssertFullSemver("1.1.0-foo.2", configuration); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo"); - fixture.AssertFullSemver("1.1.0", currentConfig); + fixture.AssertFullSemver("1.1.0", configuration); } [Test] public void VerifyIncrementConfigIsHonoured() { - var minorIncrementConfig = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - Increment = IncrementStrategy.Minor, - Branches = new Dictionary - { - { MainBranch, new BranchConfiguration { Increment = IncrementStrategy.Minor, Name = MainBranch, Regex = MainBranch } }, - { "feature", new BranchConfiguration { Increment = IncrementStrategy.Minor, Name = "feature", Regex = "features?[/-]" } } - } - }; + var minorIncrementConfig = GitFlowConfigurationBuilder.New + .WithIncrement(IncrementStrategy.Minor) + .WithBranch("main", builder => builder + .WithVersioningMode(VersioningMode.Mainline) + .WithIncrement(null) + ) + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.Mainline) + .WithIncrement(null) + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("1"); @@ -447,12 +482,13 @@ public void VerifyIncrementConfigIsHonoured() fixture.Repository.Commit(commit.Message + " +semver: patch", commit.Author, commit.Committer, new CommitOptions { AmendPreviousCommit = true }); fixture.AssertFullSemver("1.1.2", minorIncrementConfig); + var configuration = GetConfigurationBuilder().Build(); fixture.BranchTo("feature/foo4", "foo4"); fixture.MakeACommit("5 +semver: major"); fixture.AssertFullSemver("2.0.0-foo4.1", minorIncrementConfig); fixture.Checkout(MainBranch); fixture.MergeNoFF("feature/foo4"); - fixture.AssertFullSemver("2.0.0", this.configuration); + fixture.AssertFullSemver("2.0.0", configuration); // We should evaluate any commits not included in merge commit calculations for direct commit/push or squash to merge commits fixture.MakeACommit("6 +semver: major"); @@ -482,29 +518,34 @@ public void VerifyIncrementConfigIsHonoured() [Test] public void BranchWithoutMergeBaseMainlineBranchIsFound() { - var currentConfig = new GitVersionConfiguration { VersioningMode = VersioningMode.Mainline, AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatchTag }; + var configuration = GetConfigurationBuilder() + .WithBranch("unknown", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithAssemblyFileVersioningScheme(AssemblyFileVersioningScheme.MajorMinorPatchTag) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("0.0.1", currentConfig); - Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("master")); + fixture.AssertFullSemver("0.0.1", configuration); + fixture.BranchTo("master"); fixture.Repository.Branches.Remove(fixture.Repository.Branches["main"]); - fixture.AssertFullSemver("0.0.1", currentConfig); + fixture.AssertFullSemver("0.0.1", configuration); fixture.Repository.MakeCommits(2); - fixture.AssertFullSemver("0.0.3", currentConfig); - Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("issue-branch")); + fixture.AssertFullSemver("0.0.3", configuration); + fixture.BranchTo("issue-branch"); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("0.0.4-issue-branch.1", currentConfig); + fixture.AssertFullSemver("0.0.4-issue-branch.1", configuration); } [Test] public void GivenARemoteGitRepositoryWithCommitsThenClonedLocalDevelopShouldMatchRemoteVersion() { + var configuration = GetConfigurationBuilder().Build(); + using var fixture = new RemoteRepositoryFixture(); fixture.AssertFullSemver("0.0.5", configuration); // RemoteRepositoryFixture creates 5 commits. fixture.BranchTo("develop"); fixture.AssertFullSemver("0.1.0-alpha.0", configuration); - Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); + fixture.Repository.DumpGraph(); var local = fixture.CloneRepository(); fixture.AssertFullSemver("0.1.0-alpha.0", configuration, repository: local.Repository); local.Repository.DumpGraph(); @@ -517,10 +558,10 @@ public void GivenNoMainThrowsWarning() fixture.Repository.MakeACommit(); fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.MakeACommit(); - Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop")); - fixture.Repository.Branches.Remove(fixture.Repository.Branches["main"]); + fixture.BranchTo("develop"); + fixture.Repository.Branches.Remove("main"); - var exception = Assert.Throws(() => fixture.AssertFullSemver("1.1.0-alpha.1", configuration)); + var exception = Assert.Throws(() => fixture.AssertFullSemver("1.1.0-alpha.1", GetConfigurationBuilder().Build())); exception.ShouldNotBeNull(); exception.Message.ShouldMatch("No branches can be found matching the commit .* in the configured Mainline branches: main, support"); } @@ -531,13 +572,12 @@ public void GivenNoMainThrowsWarning() public void NoBumpMessageTakesPrecedenceOverBumpMessage(string commitMessage) { // Same configuration as found here: https://gitversion.net/docs/reference/version-increments#conventional-commit-messages - var conventionalCommitsConfig = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - MajorVersionBumpMessage = "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)", - MinorVersionBumpMessage = "^(feat)(\\([\\w\\s-]*\\))?:", - PatchVersionBumpMessage = "^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:", - }; + var conventionalCommitsConfig = GetConfigurationBuilder() + .WithMajorVersionBumpMessage("^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)") + .WithMinorVersionBumpMessage("^(feat)(\\([\\w\\s-]*\\))?:") + .WithPatchVersionBumpMessage("^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:") + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.MakeATaggedCommit("1.0.0"); @@ -545,28 +585,4 @@ public void NoBumpMessageTakesPrecedenceOverBumpMessage(string commitMessage) fixture.AssertFullSemver("1.0.0", conventionalCommitsConfig); } - -} - -internal static class CommitExtensions -{ - public static void MakeACommit(this RepositoryFixtureBase fixture, string commitMsg) - { - fixture.Repository.MakeACommit(commitMsg); - var diagramBuilder = (StringBuilder?)typeof(SequenceDiagram) - .GetField("diagramBuilder", BindingFlags.Instance | BindingFlags.NonPublic) - ?.GetValue(fixture.SequenceDiagram); - - string? GetParticipant(string participant) => - (string?)typeof(SequenceDiagram).GetMethod("GetParticipant", BindingFlags.Instance | BindingFlags.NonPublic) - ?.Invoke(fixture.SequenceDiagram, - new object[] - { - participant - }); - - var participant = GetParticipant(fixture.Repository.Head.FriendlyName); - if (participant != null) - diagramBuilder?.AppendLineFormat("{0} -> {0}: Commit '{1}'", participant, commitMsg); - } } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs index 9f833a51ea..21f6144152 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs @@ -55,24 +55,15 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged() [TestCase("alpha", "JIRA-123", "alpha")] [TestCase("useBranchName", "JIRA-123", "JIRA-123")] [TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")] - public void TagIsBranchNameForBranchesWithoutPrefixedBranchName(string tag, string branchName, string preReleaseTagName) + public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label, string branchName, string preReleaseTagName) { - var configuration = new GitVersionConfiguration - { - Branches = - { - { - "other", - new BranchConfiguration - { - Increment = IncrementStrategy.Patch, - Regex = ".*", - SourceBranches = new HashSet(), - Label = tag - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("other", builder => builder + .WithIncrement(IncrementStrategy.Patch) + .WithRegex(".*") + .WithSourceBranches() + .WithLabel(label)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs index 3736112c9c..c487f235a4 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -97,10 +97,7 @@ public void CanTakePreReleaseVersionFromReleasesBranchWithNumericPreReleaseTag() [Test] public void ReleaseBranchWithNextVersionSetInConfig() { - var configuration = new GitVersionConfiguration - { - NextVersion = "2.0.0" - }; + var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("2.0.0").Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeCommits(5); fixture.BranchTo("release-2.0.0"); @@ -111,15 +108,12 @@ public void ReleaseBranchWithNextVersionSetInConfig() } [Test] - public void CanTakeVersionFromReleaseBranchWithTagOverridden() + public void CanTakeVersionFromReleaseBranchWithLabelOverridden() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { "release", new BranchConfiguration { Label = "rc" } } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("release", builder => builder.WithLabel("rc")) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.3"); fixture.Repository.MakeCommits(5); @@ -312,10 +306,9 @@ public void WhenMergingReleaseBackToDevShouldNotResetBetaVersion() [Test] public void HotfixOffReleaseBranchShouldNotResetCount() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); @@ -349,11 +342,11 @@ public void HotfixOffReleaseBranchShouldNotResetCount() [Test] public void MergeOnReleaseBranchShouldNotResetCount() { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); + using var fixture = new EmptyRepositoryFixture(); const string taggedVersion = "1.0.3"; fixture.Repository.MakeATaggedCommit(taggedVersion); @@ -379,10 +372,9 @@ public void MergeOnReleaseBranchShouldNotResetCount() [Test] public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit("initial"); @@ -435,10 +427,9 @@ public void CommitOnDevelopAfterReleaseBranchMergeToDevelopShouldNotResetCount() [Test] public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("initial"); @@ -510,10 +501,9 @@ public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion() [Test] public void FeatureFromReleaseBranchShouldNotResetCount() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit("initial"); @@ -557,21 +547,11 @@ public void FeatureFromReleaseBranchShouldNotResetCount() [Test] public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight() { - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - Branches = - { - { - "release", new BranchConfiguration - { - PreReleaseWeight = 1000 - } - } - } - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") + .WithBranch("release", builder => builder.WithPreReleaseWeight(1000)) .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeATaggedCommit("1.0.3"); fixture.Repository.MakeCommits(5); @@ -585,11 +565,8 @@ public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight() [Test] public void AssemblySemFileVerShouldBeWeightedByDefaultPreReleaseWeight() { - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}" - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") .Build(); using var fixture = new EmptyRepositoryFixture(); @@ -607,11 +584,10 @@ public void AssemblySemFileVerShouldBeWeightedByDefaultPreReleaseWeight() [Test] public void FeatureOnReleaseFeatureBranchDeleted() { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string release450 = "release/4.5.0"; @@ -642,11 +618,10 @@ public void FeatureOnReleaseFeatureBranchDeleted() [Test] public void FeatureOnReleaseFeatureBranchNotDeleted() { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, - VersioningMode = VersioningMode.ContinuousDeployment - }; + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .Build(); using var fixture = new EmptyRepositoryFixture(); const string release450 = "release/4.5.0"; diff --git a/src/GitVersion.Core.Tests/IntegrationTests/RepositoryFixtureExtensions.cs b/src/GitVersion.Core.Tests/IntegrationTests/RepositoryFixtureExtensions.cs new file mode 100644 index 0000000000..0f5389fe00 --- /dev/null +++ b/src/GitVersion.Core.Tests/IntegrationTests/RepositoryFixtureExtensions.cs @@ -0,0 +1,26 @@ +using GitVersion.Extensions; + +namespace GitVersion.Core.Tests.IntegrationTests; + +internal static class RepositoryFixtureExtensions +{ + public static void MakeACommit(this RepositoryFixtureBase fixture, string commitMsg) + { + fixture.Repository.MakeACommit(commitMsg); + var diagramBuilder = (StringBuilder?)typeof(SequenceDiagram) + .GetField("diagramBuilder", BindingFlags.Instance | BindingFlags.NonPublic) + ?.GetValue(fixture.SequenceDiagram); + + string? GetParticipant(string participant) => + (string?)typeof(SequenceDiagram).GetMethod("GetParticipant", BindingFlags.Instance | BindingFlags.NonPublic) + ?.Invoke(fixture.SequenceDiagram, + new object[] + { + participant + }); + + var participant = GetParticipant(fixture.Repository.Head.FriendlyName); + if (participant != null) + diagramBuilder?.AppendLineFormat("{0} -> {0}: Commit '{1}'", participant, commitMsg); + } +} diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs index 2bd9ba67bf..3310775525 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs @@ -9,21 +9,12 @@ namespace GitVersion.Core.Tests.IntegrationTests; public class VersionBumpingScenarios : TestBase { [Test] - public void AppliedPrereleaseTagCausesBump() + public void AppliedPreReleaseLabelCausesBump() { - var configuration = new GitVersionConfiguration - { - Branches = - { - { - MainBranch, new BranchConfiguration - { - Label = "pre", - SourceBranches = new HashSet() - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder.WithLabel("pre").WithSourceBranches()) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); fixture.Repository.MakeATaggedCommit("1.0.0-pre.1"); @@ -88,19 +79,17 @@ public void CanUseCommitMessagesToBumpVersion_TagTakesPriority() [TestCase("feat: Major update\n\nSome descriptive text\nWith a second line\n\nBREAKING CHANGE: A reason", "2.0.0")] public void CanUseConventionalCommitsToBumpVersion(string commitMessage, string expectedVersion) { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - + var configuration = GitFlowConfigurationBuilder.New // For future debugging of this regex: https://regex101.com/r/CRoBol/2 - MajorVersionBumpMessage = "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)", - + .WithMajorVersionBumpMessage("^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)") // For future debugging of this regex: https://regex101.com/r/9ccNam/3 - MinorVersionBumpMessage = "^(feat)(\\([\\w\\s-]*\\))?:", - + .WithMinorVersionBumpMessage("^(feat)(\\([\\w\\s-]*\\))?:") // For future debugging of this regex: https://regex101.com/r/oFpqxA/2 - PatchVersionBumpMessage = "^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:" - }; + .WithPatchVersionBumpMessage("^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:") + .WithVersioningMode(VersioningMode.Mainline) + .WithBranch("develop", builder => builder.WithVersioningMode(null)) + .Build(); + using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); fixture.MakeATaggedCommit("1.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs index c2038e79ce..c3102ca145 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs @@ -28,10 +28,9 @@ public void DoesNotTakeVersionFromNameOfNonReleaseBranch() [Test] public void TakesVersionFromNameOfBranchThatIsReleaseByConfig() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary { { "support", new BranchConfiguration { IsReleaseBranch = true } } } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("support", builder => builder.WithIsReleaseBranch(true)) + .Build(); using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); fixture.BranchTo("support/2.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs index 04fa5a0f4b..e700c67038 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs @@ -29,10 +29,9 @@ public void DoesNotTakeVersionFromNameOfNonReleaseBranch() [Test] public void TakesVersionFromNameOfBranchThatIsReleaseByConfig() { - var configuration = new GitVersionConfiguration - { - Branches = new Dictionary { { "support", new BranchConfiguration { IsReleaseBranch = true } } } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("support", builder => builder.WithIsReleaseBranch(true)) + .Build(); using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); fixture.CreateAndMergeBranchIntoDevelop("support/2.0.0"); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs index eda561f16b..5e194224a8 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionInTagScenarios.cs @@ -11,11 +11,8 @@ internal class VersionInTagScenarios public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheDefaultValue() { // Arrange - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}" - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") .Build(); // Act @@ -28,15 +25,12 @@ public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreRe } [Test] - public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + public void LabelPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheSameAsTheLabelPreReleaseWeight() { // Arrange - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - LabelPreReleaseWeight = 65535 - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") + .WithLabelPreReleaseWeight(65535) .Build(); // Act @@ -49,16 +43,13 @@ public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreRelea } [Test] - public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + public void LabelPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheSameAsTheLabelPreReleaseWeight() { // Arrange - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - LabelPreReleaseWeight = 65535, - VersioningMode = VersioningMode.ContinuousDeployment - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") + .WithLabelPreReleaseWeight(65535) + .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); // Act @@ -81,12 +72,9 @@ public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPre public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheDefaultValue() { // Arrange - var configuration = new ConfigurationBuilder() - .Add(new GitVersionConfiguration - { - AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - VersioningMode = VersioningMode.ContinuousDeployment - }) + var configuration = GitFlowConfigurationBuilder.New + .WithAssemblyFileVersioningFormat("{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}") + .WithVersioningMode(VersioningMode.ContinuousDeployment) .Build(); // Act diff --git a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs index d8406630ad..eafcb511fc 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs @@ -1,6 +1,5 @@ using GitVersion.Common; using GitVersion.Configuration; -using GitVersion.Core.Tests.Helpers; using GitVersion.Logging; using GitVersion.VersionCalculation; @@ -41,11 +40,9 @@ public void When_getting_configurations_of_a_branch_with_versioning_mode_Given_f var mainBranchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var developBranchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New - .WithoutVersioningMode() + .WithVersioningMode(null) .WithBranch("main", builder => builder.WithVersioningMode(versioningMode)) - .WithBranch("develop", builder => builder - .WithVersioningMode(null).WithIncrement(IncrementStrategy.Inherit) - ) + .WithBranch("develop", builder => builder.WithVersioningMode(null).WithIncrement(IncrementStrategy.Inherit)) .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(developBranchMock, configuration, Arg.Any>()).Returns(new[] { mainBranchMock }); @@ -68,7 +65,8 @@ public void When_getting_configurations_of_a_branch_with_versioning_mode_Given_p // Arrange var mainBranchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var developBranchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.WithoutVersioningMode() + var configuration = GitFlowConfigurationBuilder.New + .WithVersioningMode(null) .WithBranch("main", builder => builder.WithVersioningMode(versioningMode)) .WithBranch("develop", builder => builder .WithVersioningMode(VersioningMode.ContinuousDelivery).WithIncrement(IncrementStrategy.Inherit) @@ -103,9 +101,9 @@ public void When_getting_configurations_of_a_branch_with_tag_alpha_Given_branch_ var mainBranchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var developBranchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithTag(string.Empty)) + .WithBranch("main", builder => builder.WithLabel(string.Empty)) .WithBranch("develop", builder => builder - .WithIncrement(IncrementStrategy.Inherit).WithTag("alpha") + .WithIncrement(IncrementStrategy.Inherit).WithLabel("alpha") ) .Build(); @@ -131,9 +129,9 @@ public void When_getting_configurations_of_a_branch_without_tag_Given_branch_whi var mainBranchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var developBranchMock = GitToolsTestingExtensions.CreateMockBranch("develop", GitToolsTestingExtensions.CreateMockCommit()); var configuration = GitFlowConfigurationBuilder.New - .WithBranch("main", builder => builder.WithTag(string.Empty)) + .WithBranch("main", builder => builder.WithLabel(string.Empty)) .WithBranch("develop", builder => builder - .WithIncrement(IncrementStrategy.Inherit).WithTag(null) + .WithIncrement(IncrementStrategy.Inherit).WithLabel(null) ) .Build(); @@ -153,7 +151,7 @@ public void When_getting_configurations_of_a_branch_without_tag_Given_branch_whi [TestCase("release/latest", IncrementStrategy.None, "latest")] [TestCase("release/1.0.0", IncrementStrategy.Patch, "not-latest")] - public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementStrategy incrementStrategy, string tag) + public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementStrategy incrementStrategy, string label) { // Arrange var releaseBranchMock = GitToolsTestingExtensions.CreateMockBranch(branchName, GitToolsTestingExtensions.CreateMockCommit()); @@ -167,15 +165,24 @@ public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementS IsReleaseBranch = false, SourceBranches = new HashSet() }; - var configuration = new ConfigurationBuilder().Add(new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDelivery, - Branches = - { - { "release/latest", new BranchConfiguration(branchConfiguration) { Increment = IncrementStrategy.None, Label = "latest", Regex = "release/latest" } }, - { "release", new BranchConfiguration(branchConfiguration) { Increment = IncrementStrategy.Patch, Label = "not-latest", Regex = "releases?[/-]" } } - } - }).Build(); + + var configuration = GitFlowConfigurationBuilder.New + .WithoutBranches() + .WithBranch("release/latest", builder => builder + .WithConfiguration(branchConfiguration) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithIncrement(IncrementStrategy.None) + .WithLabel("latest") + .WithRegex("release/latest") + ) + .WithBranch("release", builder => builder + .WithConfiguration(branchConfiguration) + .WithVersioningMode(VersioningMode.ContinuousDeployment) + .WithIncrement(IncrementStrategy.Patch) + .WithLabel("not-latest") + .WithRegex("releases?[/-]") + ) + .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(releaseBranchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); @@ -189,7 +196,7 @@ public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementS actual.ShouldHaveSingleItem(); actual[0].Branch.ShouldBe(releaseBranchMock); actual[0].Value.Increment.ShouldBe(incrementStrategy); - actual[0].Value.Label.ShouldBe(tag); + actual[0].Value.Label.ShouldBe(label); } [Test] @@ -268,7 +275,9 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf { // Arrange var branchMock = GitToolsTestingExtensions.CreateMockBranch("unknown", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.WithIncrement(null).Build(); + var configuration = GitFlowConfigurationBuilder.New + .WithIncrement(null) + .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); @@ -290,7 +299,9 @@ public void When_getting_configurations_of_an_unknown_branch_Given_fallback_conf { // Arrange var branchMock = GitToolsTestingExtensions.CreateMockBranch("unknown", GitToolsTestingExtensions.CreateMockCommit()); - var configuration = GitFlowConfigurationBuilder.New.WithIncrement(fallbackIncrement).Build(); + var configuration = GitFlowConfigurationBuilder.New + .WithIncrement(fallbackIncrement) + .Build(); var repositoryStoreMock = Substitute.For(); repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs index 0492703e0e..160b84313e 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -32,7 +32,11 @@ public void DoesNotIncrementWhenBaseVersionSaysNotTo() { var contextBuilder = new GitVersionContextBuilder(); - contextBuilder.WithConfig(new GitVersionConfiguration() { NextVersion = "1.0.0" }).Build(); + var overrideConfiguration = new Dictionary() + { + { "next-version", "1.0.0" } + }; + contextBuilder.WithOverrideConfiguration(overrideConfiguration).Build(); contextBuilder.ServicesProvider.ShouldNotBeNull(); var nextVersionCalculator = contextBuilder.ServicesProvider.GetRequiredService(); @@ -61,23 +65,16 @@ public void AppliesBranchPreReleaseTag() } [Test] - public void PreReleaseTagCanUseBranchName() + public void PreReleaseLabelCanUseBranchName() { - var configuration = new GitVersionConfiguration - { - NextVersion = "1.0.0", - Branches = new Dictionary - { - { - "custom", new BranchConfiguration - { - Regex = "custom/", - Label = "useBranchName", - SourceBranches = new HashSet() - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") + .WithBranch("custom", builder => builder + .WithRegex("custom/") + .WithLabel("{BranchName}") + .WithSourceBranches() + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -92,11 +89,11 @@ public void PreReleaseTagCanUseBranchName() [Test] public void PreReleaseVersionMainline() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - NextVersion = "1.0.0" - }; + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") + .WithBranch("unknown", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -109,11 +106,10 @@ public void PreReleaseVersionMainline() [Test] public void MergeIntoMainline() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - NextVersion = "1.0.0" - }; + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -128,10 +124,10 @@ public void MergeIntoMainline() [Test] public void MergeFeatureIntoMainline() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -151,16 +147,15 @@ public void MergeFeatureIntoMainline() [Test] public void MergeFeatureIntoMainlineWithMinorIncrement() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - Branches = new Dictionary - { - { "feature", new BranchConfiguration { Increment = IncrementStrategy.Minor } } - }, - Ignore = new IgnoreConfiguration { Shas = new List() }, - MergeMessageFormats = new Dictionary() - }; + var configuration = GitFlowConfigurationBuilder.New + .WithIgnoreConfiguration(new()) + .WithMergeMessageFormats(new()) + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.Mainline) + .WithIncrement(IncrementStrategy.Minor) + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -180,16 +175,15 @@ public void MergeFeatureIntoMainlineWithMinorIncrement() [Test] public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - Branches = new Dictionary - { - { "feature", new BranchConfiguration { Increment = IncrementStrategy.Minor } } - }, - Ignore = new IgnoreConfiguration { Shas = new List() }, - MergeMessageFormats = new Dictionary() - }; + var configuration = GitFlowConfigurationBuilder.New + .WithIgnoreConfiguration(new()) + .WithMergeMessageFormats(new()) + .WithVersioningMode(VersioningMode.Mainline) + .WithBranch("feature", builder => builder + .WithIncrement(IncrementStrategy.Minor) + .WithVersioningMode(VersioningMode.Mainline)) + .WithBranch("hotfix", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -217,23 +211,16 @@ public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix() } [Test] - public void PreReleaseTagCanUseBranchNameVariable() + public void PreReleaseLabelCanUseBranchNameVariable() { - var configuration = new GitVersionConfiguration - { - NextVersion = "1.0.0", - Branches = new Dictionary - { - { - "custom", new BranchConfiguration - { - Regex = "custom/", - Label = "alpha.{BranchName}", - SourceBranches = new HashSet() - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") + .WithBranch("custom", builder => builder + .WithRegex("custom/") + .WithLabel("alpha.{BranchName}") + .WithSourceBranches() + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit(); @@ -248,19 +235,12 @@ public void PreReleaseTagCanUseBranchNameVariable() [Test] public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.ContinuousDelivery, - Branches = new Dictionary - { - { - MainBranch, new BranchConfiguration - { - Label = "beta" - } - } - } - }; + var configuration = GitFlowConfigurationBuilder.New + .WithBranch("main", builder => builder.WithLabel("beta")) + .WithBranch("feature", builder => builder + .WithVersioningMode(VersioningMode.ContinuousDelivery) + ) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); @@ -281,11 +261,10 @@ public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery() [Test] public void GetNextVersionOnNonMainlineBranchWithoutCommitsShouldWorkNormally() { - var configuration = new GitVersionConfiguration - { - VersioningMode = VersioningMode.Mainline, - NextVersion = "1.0.0" - }; + var configuration = GitFlowConfigurationBuilder.New + .WithNextVersion("1.0.0") + .WithBranch("feature", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); using var fixture = new EmptyRepositoryFixture(); fixture.MakeACommit("initial commit"); @@ -456,7 +435,9 @@ public void ShouldIgnorePreReleaseVersionInMainlineMode() // Arrange var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude()); - var configuration = GitFlowConfigurationBuilder.New.WithIgnoreConfiguration(fakeIgnoreConfig).WithVersioningMode(VersioningMode.Mainline).Build(); + var configuration = GitFlowConfigurationBuilder.New.WithIgnoreConfiguration(fakeIgnoreConfig) + .WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline)) + .Build(); var context = new GitVersionContext(branchMock, null, configuration, null, 0); var repositoryStoreMock = Substitute.For(); var effectiveConfiguration = context.GetEffectiveConfiguration(branchMock); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs index e4f05b958d..2c22ee5a53 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs @@ -24,7 +24,12 @@ public void ReturnsNullWhenNoNextVersionIsInConfig() [TestCase("0.1", "0.1.0", SemanticVersionFormat.Loose)] public void ConfigNextVersionTest(string nextVersion, string expectedVersion, SemanticVersionFormat versionFormat) { - var baseVersion = GetBaseVersion(new GitVersionConfiguration { NextVersion = nextVersion, SemanticVersionFormat = versionFormat }); + var overrideConfiguration = new Dictionary() + { + { "next-version", nextVersion }, + { "semantic-version-format", versionFormat } + }; + var baseVersion = GetBaseVersion(overrideConfiguration); baseVersion.ShouldNotBeNull(); baseVersion.ShouldIncrement.ShouldBe(false); @@ -33,25 +38,20 @@ public void ConfigNextVersionTest(string nextVersion, string expectedVersion, Se [TestCase("0.1", SemanticVersionFormat.Strict)] public void ConfigNextVersionTestShouldFail(string nextVersion, SemanticVersionFormat versionFormat) - => - Should.Throw(() - => GetBaseVersion(new GitVersionConfiguration - { - NextVersion = nextVersion, - SemanticVersionFormat = versionFormat - })) - .Message.ShouldBe($"Failed to parse {nextVersion} into a Semantic Version"); - - - private static BaseVersion? GetBaseVersion(GitVersionConfiguration? configuration = null) { - var contextBuilder = new GitVersionContextBuilder(); - - if (configuration != null) + var overrideConfiguration = new Dictionary() { - contextBuilder = contextBuilder.WithConfig(configuration); - } + { "next-version", nextVersion }, + { "semantic-version-format", versionFormat } + }; + Should.Throw(() => GetBaseVersion(overrideConfiguration)) + .Message.ShouldBe($"Failed to parse {nextVersion} into a Semantic Version"); + } + + private static BaseVersion? GetBaseVersion(IReadOnlyDictionary? overrideConfiguration = null) + { + var contextBuilder = new GitVersionContextBuilder().WithOverrideConfiguration(overrideConfiguration); contextBuilder.Build(); contextBuilder.ServicesProvider.ShouldNotBeNull(); var strategy = contextBuilder.ServicesProvider.GetServiceForType(); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs index 6cc840305b..9fc2cb4a30 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs @@ -145,14 +145,18 @@ public void ShouldNotTakeVersionFromUnrelatedMerge(string commitMessage) [TestCase("Merge branch 'release/2.0.0'", null, "2.0.0")] public void TakesVersionFromMergeOfConfiguredReleaseBranch(string message, string? releaseBranch, string expectedVersion) { - var configuration = new GitVersionConfiguration(); - if (releaseBranch != null) configuration.Branches[releaseBranch] = new BranchConfiguration { IsReleaseBranch = true }; + var configurationBuilder = GitFlowConfigurationBuilder.New; + if (releaseBranch != null) + { + configurationBuilder.WithBranch(releaseBranch, builder => builder.WithIsReleaseBranch(true)); + } + ConfigurationHelper configurationHelper = new(configurationBuilder.Build()); var parents = GetParents(true); - AssertMergeMessage(message, expectedVersion, parents, configuration); + AssertMergeMessage(message, expectedVersion, parents, configurationHelper.Dictionary); } - private static void AssertMergeMessage(string message, string? expectedVersion, IEnumerable parents, GitVersionConfiguration? configuration = null) + private static void AssertMergeMessage(string message, string? expectedVersion, IEnumerable parents, IReadOnlyDictionary? configuration = null) { var commit = GitToolsTestingExtensions.CreateMockCommit(); commit.Message.Returns(message); @@ -165,7 +169,8 @@ private static void AssertMergeMessage(string message, string? expectedVersion, mockRepository.Commits.Returns(mockBranch.Commits); var contextBuilder = new GitVersionContextBuilder() - .WithConfig(configuration ?? new GitVersionConfiguration()).WithRepository(mockRepository); + .WithOverrideConfiguration(configuration) + .WithRepository(mockRepository); contextBuilder.Build(); contextBuilder.ServicesProvider.ShouldNotBeNull(); var strategy = contextBuilder.ServicesProvider.GetServiceForType(); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs index 985279d74c..42712fbaee 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs @@ -43,6 +43,7 @@ public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName) var strategy = GetVersionStrategy(fixture.RepositoryPath, gitRepository, branchName); var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); + branchConfiguration = branchConfiguration.Inherit(configuration.GetFallbackBranchConfiguration()); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); strategy.ShouldNotBeNull(); @@ -59,11 +60,12 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s fixture.Repository.MakeACommit(); fixture.Repository.CreateBranch(branchName); - var configurationBuilder = new ConfigurationBuilder() - .Add(new GitVersionConfiguration { Branches = { { "support", new BranchConfiguration { IsReleaseBranch = true } } } }); + var configurationBuilder = GitFlowConfigurationBuilder.New + .WithBranch("support", builder => builder.WithIsReleaseBranch(true)); + ConfigurationHelper configurationHelper = new(configurationBuilder.Build()); var gitRepository = fixture.Repository.ToGitRepository(); - var strategy = GetVersionStrategy(fixture.RepositoryPath, gitRepository, branchName, configurationBuilder.Build()); + var strategy = GetVersionStrategy(fixture.RepositoryPath, gitRepository, branchName, configurationHelper.Dictionary); var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); @@ -100,9 +102,9 @@ public void CanTakeVersionFromNameOfRemoteReleaseBranch(string branchName, strin baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); } - private static IVersionStrategy GetVersionStrategy(string workingDirectory, IGitRepository repository, string branch, GitVersionConfiguration? configuration = null) + private static IVersionStrategy GetVersionStrategy(string workingDirectory, IGitRepository repository, string branch, IReadOnlyDictionary? overrideConfiguration = null) { - var sp = BuildServiceProvider(workingDirectory, repository, branch, configuration); + var sp = BuildServiceProvider(workingDirectory, repository, branch, overrideConfiguration); return sp.GetServiceForType(); } } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs index 805e4dddda..8338a81073 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs @@ -115,7 +115,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStable() semVer.BuildMetaData.ShortSha = "commitShortSha"; semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z"); - var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment); + var configuration = new TestEffectiveConfiguration( + label: "ci", versioningMode: VersioningMode.ContinuousDeployment + ); var vars = this.variableProvider.GetVariablesFor(semVer, configuration, false); diff --git a/src/GitVersion.Core/ConfigInfo.cs b/src/GitVersion.Core/ConfigInfo.cs index 799e1c1378..907a04bfdf 100644 --- a/src/GitVersion.Core/ConfigInfo.cs +++ b/src/GitVersion.Core/ConfigInfo.cs @@ -1,10 +1,8 @@ -using GitVersion.Configuration; - namespace GitVersion; public class ConfigInfo { public string? ConfigFile; - public GitVersionConfiguration? OverrideConfig; + public IReadOnlyDictionary? OverrideConfiguration; public bool ShowConfig; } diff --git a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs index d41dc80bbf..fce68b6abf 100644 --- a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs +++ b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs @@ -9,4 +9,5 @@ public interface IConfigurationFileLocator void Verify(string workingDirectory, string projectRootDirectory); string? SelectConfigFilePath(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo); GitVersionConfiguration ReadConfig(string workingDirectory); + IReadOnlyDictionary? ReadOverrideConfiguration(string? workingDirectory); } diff --git a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationProvider.cs b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationProvider.cs index 245bafac06..923200c42d 100644 --- a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationProvider.cs +++ b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationProvider.cs @@ -2,6 +2,6 @@ namespace GitVersion.Configuration; public interface IConfigurationProvider { - GitVersionConfiguration Provide(GitVersionConfiguration? overrideConfiguration = null); + GitVersionConfiguration Provide(IReadOnlyDictionary? overrideConfiguration = null); void Init(string workingDirectory); } diff --git a/src/GitVersion.Core/Configuration/BranchConfiguration.cs b/src/GitVersion.Core/Configuration/BranchConfiguration.cs index 876e5e27f4..50d6cfba1b 100644 --- a/src/GitVersion.Core/Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Core/Configuration/BranchConfiguration.cs @@ -9,9 +9,6 @@ public BranchConfiguration() { } - /// - /// Creates a clone of the given . - /// public BranchConfiguration(BranchConfiguration branchConfiguration) { VersioningMode = branchConfiguration.VersioningMode; @@ -43,31 +40,6 @@ public BranchConfiguration(BranchConfiguration branchConfiguration) [YamlMember(Alias = "increment")] public IncrementStrategy? Increment { get; set; } - public BranchConfiguration Inherit(BranchConfiguration? parentConfig) - { - if (parentConfig is null) return this; - - var result = new BranchConfiguration(this); - - if (result.Increment is null || result.Increment == IncrementStrategy.Inherit) - result.Increment = parentConfig.Increment; - result.VersioningMode ??= parentConfig.VersioningMode; - result.Label ??= parentConfig.Label; - result.PreventIncrementOfMergedBranchVersion ??= parentConfig.PreventIncrementOfMergedBranchVersion; - result.LabelNumberPattern ??= parentConfig.LabelNumberPattern; - result.TrackMergeTarget ??= parentConfig.TrackMergeTarget; - result.CommitMessageIncrementing ??= parentConfig.CommitMessageIncrementing; - result.Regex ??= parentConfig.Regex; - result.SourceBranches ??= parentConfig.SourceBranches; - result.IsSourceBranchFor ??= parentConfig.IsSourceBranchFor; - result.TracksReleaseBranches ??= parentConfig.TracksReleaseBranches; - result.IsReleaseBranch ??= parentConfig.IsReleaseBranch; - result.IsMainline ??= parentConfig.IsMainline; - result.PreReleaseWeight ??= parentConfig.PreReleaseWeight; - - return result; - } - [YamlMember(Alias = "prevent-increment-of-merged-branch-version")] public bool? PreventIncrementOfMergedBranchVersion { get; set; } @@ -107,31 +79,28 @@ public BranchConfiguration Inherit(BranchConfiguration? parentConfig) [YamlIgnore] public string Name { get; set; } - public void MergeTo(BranchConfiguration targetConfig) + public BranchConfiguration Inherit(BranchConfiguration? parentConfig) { - if (targetConfig == null) throw new ArgumentNullException(nameof(targetConfig)); - - targetConfig.VersioningMode = VersioningMode ?? targetConfig.VersioningMode; - targetConfig.Label = Label ?? targetConfig.Label; - targetConfig.Increment = Increment ?? targetConfig.Increment; - targetConfig.PreventIncrementOfMergedBranchVersion = PreventIncrementOfMergedBranchVersion ?? targetConfig.PreventIncrementOfMergedBranchVersion; - targetConfig.LabelNumberPattern = LabelNumberPattern ?? targetConfig.LabelNumberPattern; - targetConfig.TrackMergeTarget = TrackMergeTarget ?? targetConfig.TrackMergeTarget; - targetConfig.CommitMessageIncrementing = CommitMessageIncrementing ?? targetConfig.CommitMessageIncrementing; - targetConfig.Regex = Regex ?? targetConfig.Regex; - targetConfig.SourceBranches = SourceBranches ?? targetConfig.SourceBranches; - targetConfig.IsSourceBranchFor = IsSourceBranchFor ?? targetConfig.IsSourceBranchFor; - targetConfig.TracksReleaseBranches = TracksReleaseBranches ?? targetConfig.TracksReleaseBranches; - targetConfig.IsReleaseBranch = IsReleaseBranch ?? targetConfig.IsReleaseBranch; - targetConfig.IsMainline = IsMainline ?? targetConfig.IsMainline; - targetConfig.PreReleaseWeight = PreReleaseWeight ?? targetConfig.PreReleaseWeight; - } + if (parentConfig is null) return this; - public BranchConfiguration Apply(BranchConfiguration overrides) - { - if (overrides == null) throw new ArgumentNullException(nameof(overrides)); + var result = new BranchConfiguration(this); + + if (result.Increment is null || result.Increment == IncrementStrategy.Inherit) + result.Increment = parentConfig.Increment; + result.VersioningMode ??= parentConfig.VersioningMode; + result.Label ??= parentConfig.Label; + result.PreventIncrementOfMergedBranchVersion ??= parentConfig.PreventIncrementOfMergedBranchVersion; + result.LabelNumberPattern ??= parentConfig.LabelNumberPattern; + result.TrackMergeTarget ??= parentConfig.TrackMergeTarget; + result.CommitMessageIncrementing ??= parentConfig.CommitMessageIncrementing; + result.Regex ??= parentConfig.Regex; + result.SourceBranches ??= parentConfig.SourceBranches; + result.IsSourceBranchFor ??= parentConfig.IsSourceBranchFor; + result.TracksReleaseBranches ??= parentConfig.TracksReleaseBranches; + result.IsReleaseBranch ??= parentConfig.IsReleaseBranch; + result.IsMainline ??= parentConfig.IsMainline; + result.PreReleaseWeight ??= parentConfig.PreReleaseWeight; - overrides.MergeTo(this); - return this; + return result; } } diff --git a/src/GitVersion.Core.Tests/Helpers/TestBranchConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs similarity index 53% rename from src/GitVersion.Core.Tests/Helpers/TestBranchConfigurationBuilder.cs rename to src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs index 09a0952670..eef5651d68 100644 --- a/src/GitVersion.Core.Tests/Helpers/TestBranchConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/BranchConfigurationBuilder.cs @@ -1,18 +1,17 @@ -using GitVersion.Configuration; using GitVersion.VersionCalculation; -namespace GitVersion.Core.Tests.Helpers; +namespace GitVersion.Configuration; -public class TestBranchConfigurationBuilder +public class BranchConfigurationBuilder { - public static TestBranchConfigurationBuilder New => new(); + public static BranchConfigurationBuilder New => new(); private string name; private VersioningMode? versioningMode; - private string? tag; + private string? label; private IncrementStrategy? increment; private bool? preventIncrementOfMergedBranchVersion; - private string? tagNumberPattern; + private string? labelNumberPattern; private bool? trackMergeTarget; private CommitMessageIncrementMode? commitMessageIncrementing; private string? regex; @@ -23,118 +22,120 @@ public class TestBranchConfigurationBuilder private bool? isMainline; private int? preReleaseWeight; - private TestBranchConfigurationBuilder() => this.name = "Just-A-Test"; + private BranchConfigurationBuilder() + { + } - public virtual TestBranchConfigurationBuilder WithName(string value) + public virtual BranchConfigurationBuilder WithName(string value) { this.name = value; return this; } - public virtual TestBranchConfigurationBuilder WithVersioningMode(VersioningMode? value) + public virtual BranchConfigurationBuilder WithVersioningMode(VersioningMode? value) { this.versioningMode = value; return this; } - public virtual TestBranchConfigurationBuilder WithTag(string? value) + public virtual BranchConfigurationBuilder WithLabel(string? value) { - this.tag = value; + this.label = value; return this; } - public virtual TestBranchConfigurationBuilder WithIncrement(IncrementStrategy? value) + public virtual BranchConfigurationBuilder WithIncrement(IncrementStrategy? value) { this.increment = value; return this; } - public virtual TestBranchConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(bool? value) + public virtual BranchConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(bool? value) { this.preventIncrementOfMergedBranchVersion = value; return this; } - public virtual TestBranchConfigurationBuilder WithTagNumberPattern(string? value) + public virtual BranchConfigurationBuilder WithLabelNumberPattern(string? value) { - this.tagNumberPattern = value; + this.labelNumberPattern = value; return this; } - public virtual TestBranchConfigurationBuilder WithTrackMergeTarget(bool? value) + public virtual BranchConfigurationBuilder WithTrackMergeTarget(bool? value) { this.trackMergeTarget = value; return this; } - public virtual TestBranchConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value) + public virtual BranchConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value) { this.commitMessageIncrementing = value; return this; } - public virtual TestBranchConfigurationBuilder WithRegex(string? value) + public virtual BranchConfigurationBuilder WithRegex(string? value) { this.regex = value; return this; } - public virtual TestBranchConfigurationBuilder WithSourceBranches(IEnumerable values) + public virtual BranchConfigurationBuilder WithSourceBranches(IEnumerable? values) { - WithSourceBranches(values.ToArray()); + WithSourceBranches(values?.ToArray()); return this; } - public virtual TestBranchConfigurationBuilder WithSourceBranches(params string[] values) + public virtual BranchConfigurationBuilder WithSourceBranches(params string[]? values) { - this.sourceBranches = new HashSet(values); + this.sourceBranches = values == null ? null : new HashSet(values); return this; } - public virtual TestBranchConfigurationBuilder WithIsSourceBranchFor(IEnumerable values) + public virtual BranchConfigurationBuilder WithIsSourceBranchFor(IEnumerable? values) { - WithIsSourceBranchFor(values.ToArray()); + WithIsSourceBranchFor(values?.ToArray()); return this; } - public virtual TestBranchConfigurationBuilder WithIsSourceBranchFor(params string[] values) + public virtual BranchConfigurationBuilder WithIsSourceBranchFor(params string[]? values) { - this.isSourceBranchFor = new HashSet(values); + this.isSourceBranchFor = values == null ? null : new HashSet(values); return this; } - public virtual TestBranchConfigurationBuilder WithTracksReleaseBranches(bool? value) + public virtual BranchConfigurationBuilder WithTracksReleaseBranches(bool? value) { this.tracksReleaseBranches = value; return this; } - public virtual TestBranchConfigurationBuilder WithIsReleaseBranch(bool? value) + public virtual BranchConfigurationBuilder WithIsReleaseBranch(bool? value) { this.isReleaseBranch = value; return this; } - public virtual TestBranchConfigurationBuilder WithIsMainline(bool? value) + public virtual BranchConfigurationBuilder WithIsMainline(bool? value) { this.isMainline = value; return this; } - public virtual TestBranchConfigurationBuilder WithPreReleaseWeight(int? value) + public virtual BranchConfigurationBuilder WithPreReleaseWeight(int? value) { this.preReleaseWeight = value; return this; } - public virtual TestBranchConfigurationBuilder WithConfiguration(BranchConfiguration value) + public virtual BranchConfigurationBuilder WithConfiguration(BranchConfiguration value) { WithName(value.Name); WithVersioningMode(value.VersioningMode); - WithTag(value.Label); + WithLabel(value.Label); WithIncrement(value.Increment); WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); - WithTagNumberPattern(value.LabelNumberPattern); + WithLabelNumberPattern(value.LabelNumberPattern); WithTrackMergeTarget(value.TrackMergeTarget); WithCommitMessageIncrementing(value.CommitMessageIncrementing); WithRegex(value.Regex); @@ -142,8 +143,8 @@ public virtual TestBranchConfigurationBuilder WithConfiguration(BranchConfigurat WithIsReleaseBranch(value.IsReleaseBranch); WithIsMainline(value.IsMainline); WithPreReleaseWeight(value.PreReleaseWeight); - WithSourceBranches(value.SourceBranches ?? Enumerable.Empty()); - WithIsSourceBranchFor(value.IsSourceBranchFor ?? Enumerable.Empty()); + WithSourceBranches(value.SourceBranches); + WithIsSourceBranchFor(value.IsSourceBranchFor); return this; } @@ -153,7 +154,7 @@ public BranchConfiguration Build() { Name = name, VersioningMode = versioningMode, - Label = tag, + Label = label, Increment = increment, Regex = regex, TracksReleaseBranches = tracksReleaseBranches, @@ -161,7 +162,7 @@ public BranchConfiguration Build() CommitMessageIncrementing = commitMessageIncrementing, IsMainline = isMainline, IsReleaseBranch = isReleaseBranch, - LabelNumberPattern = tagNumberPattern, + LabelNumberPattern = labelNumberPattern, PreventIncrementOfMergedBranchVersion = preventIncrementOfMergedBranchVersion, PreReleaseWeight = preReleaseWeight, SourceBranches = sourceBranches, diff --git a/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs deleted file mode 100644 index de2afcfcb0..0000000000 --- a/src/GitVersion.Core/Configuration/ConfigurationBuilder.cs +++ /dev/null @@ -1,317 +0,0 @@ -using GitVersion.Extensions; -using GitVersion.VersionCalculation; - -namespace GitVersion.Configuration; - -public class ConfigurationBuilder -{ - private const int DefaultLabelPreReleaseWeight = 60000; - - private readonly List overrides = new(); - - public ConfigurationBuilder Add(GitVersionConfiguration configuration) - { - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - - this.overrides.Add(configuration); - return this; - } - - public GitVersionConfiguration Build() - { - var configuration = CreateDefaultConfiguration(); - - foreach (var overrideConfiguration in this.overrides) - { - ApplyOverrides(configuration, overrideConfiguration); - } - - FinalizeConfiguration(configuration); - ValidateConfiguration(configuration); - - return configuration; - } - - private static void ApplyOverrides(GitVersionConfiguration targetConfig, GitVersionConfiguration overrideConfiguration) - { - targetConfig.AssemblyVersioningScheme = overrideConfiguration.AssemblyVersioningScheme ?? targetConfig.AssemblyVersioningScheme; - targetConfig.AssemblyFileVersioningScheme = overrideConfiguration.AssemblyFileVersioningScheme ?? targetConfig.AssemblyFileVersioningScheme; - targetConfig.AssemblyInformationalFormat = overrideConfiguration.AssemblyInformationalFormat ?? targetConfig.AssemblyInformationalFormat; - targetConfig.AssemblyVersioningFormat = overrideConfiguration.AssemblyVersioningFormat ?? targetConfig.AssemblyVersioningFormat; - targetConfig.AssemblyFileVersioningFormat = overrideConfiguration.AssemblyFileVersioningFormat ?? targetConfig.AssemblyFileVersioningFormat; - targetConfig.VersioningMode = overrideConfiguration.VersioningMode ?? targetConfig.VersioningMode; - targetConfig.LabelPrefix = overrideConfiguration.LabelPrefix ?? targetConfig.LabelPrefix; - targetConfig.ContinuousDeploymentFallbackLabel = overrideConfiguration.ContinuousDeploymentFallbackLabel ?? targetConfig.ContinuousDeploymentFallbackLabel; - targetConfig.NextVersion = overrideConfiguration.NextVersion ?? targetConfig.NextVersion; - targetConfig.MajorVersionBumpMessage = overrideConfiguration.MajorVersionBumpMessage ?? targetConfig.MajorVersionBumpMessage; - targetConfig.MinorVersionBumpMessage = overrideConfiguration.MinorVersionBumpMessage ?? targetConfig.MinorVersionBumpMessage; - targetConfig.PatchVersionBumpMessage = overrideConfiguration.PatchVersionBumpMessage ?? targetConfig.PatchVersionBumpMessage; - targetConfig.NoBumpMessage = overrideConfiguration.NoBumpMessage ?? targetConfig.NoBumpMessage; - targetConfig.LabelPreReleaseWeight = overrideConfiguration.LabelPreReleaseWeight ?? targetConfig.LabelPreReleaseWeight; - targetConfig.CommitMessageIncrementing = overrideConfiguration.CommitMessageIncrementing ?? targetConfig.CommitMessageIncrementing; - targetConfig.Increment = overrideConfiguration.Increment ?? targetConfig.Increment; - targetConfig.CommitDateFormat = overrideConfiguration.CommitDateFormat ?? targetConfig.CommitDateFormat; - targetConfig.MergeMessageFormats = overrideConfiguration.MergeMessageFormats.Any() ? overrideConfiguration.MergeMessageFormats : targetConfig.MergeMessageFormats; - targetConfig.UpdateBuildNumber = overrideConfiguration.UpdateBuildNumber ?? targetConfig.UpdateBuildNumber; - targetConfig.SemanticVersionFormat = overrideConfiguration.SemanticVersionFormat; - - if (overrideConfiguration.Ignore is { IsEmpty: false }) - { - targetConfig.Ignore = overrideConfiguration.Ignore; - } - - ApplyBranchOverrides(targetConfig, overrideConfiguration); - } - - private static void ApplyBranchOverrides(GitVersionConfiguration targetConfig, GitVersionConfiguration overrideConfiguration) - { - if (overrideConfiguration.Branches is { Count: > 0 }) - { - // We can't just add new configs to the targetConfig.Branches, and have to create a new dictionary. - // The reason is that GitVersion 5.3.x (and earlier) merges default configs into overrides. The new approach is opposite: we merge overrides into default configuration. - // The important difference of these approaches is the order of branches in a dictionary (we should not rely on Dictionary's implementation details, but we already did that): - // Old approach: { new-branch-1, new-branch-2, default-branch-1, default-branch-2, ... } - // New approach: { default-branch-1, default-branch-2, ..., new-branch-1, new-branch-2 } - // In case when several branch configurations match the current branch (by regex), we choose the first one. - // So we have to add new branches to the beginning of a dictionary to preserve 5.3.x behavior. - - var newBranches = new Dictionary(); - - var targetConfigBranches = targetConfig.Branches; - - foreach (var (name, branchConfiguration) in overrideConfiguration.Branches) - { - // for compatibility reason we check if it's master, we rename it to main - var branchName = name == GitVersionConfiguration.MasterBranchKey ? GitVersionConfiguration.MainBranchKey : name; - if (!targetConfigBranches.TryGetValue(branchName, out var target)) - { - target = new BranchConfiguration() { Name = branchName }; - } - - branchConfiguration.MergeTo(target); - if (target.SourceBranches != null && target.SourceBranches.Contains(GitVersionConfiguration.MasterBranchKey)) - { - target.SourceBranches.Remove(GitVersionConfiguration.MasterBranchKey); - target.SourceBranches.Add(GitVersionConfiguration.MainBranchKey); - } - newBranches[branchName] = target; - } - - foreach (var (name, branchConfiguration) in targetConfigBranches) - { - newBranches.TryAdd(name, branchConfiguration); - } - - targetConfig.Branches = newBranches; - } - } - - private static void FinalizeConfiguration(GitVersionConfiguration configuration) - { - foreach (var (name, branchConfiguration) in configuration.Branches) - { - FinalizeBranchConfiguration(configuration, name, branchConfiguration); - } - } - - private static void FinalizeBranchConfiguration(GitVersionConfiguration configuration, string name, BranchConfiguration branchConfiguration) - { - branchConfiguration.Name = name; - branchConfiguration.Increment ??= configuration.Increment ?? IncrementStrategy.Inherit; - - if (branchConfiguration.VersioningMode == null) - { - if (name == GitVersionConfiguration.DevelopBranchKey) - { - // Why this applies only on develop branch? I'm surprised that the value not coming from configuration. - branchConfiguration.VersioningMode = configuration.VersioningMode == VersioningMode.Mainline ? VersioningMode.Mainline : VersioningMode.ContinuousDeployment; - } - else - { - branchConfiguration.VersioningMode = configuration.VersioningMode; - } - } - - if (branchConfiguration.IsSourceBranchFor == null) - return; - - foreach (var targetBranchName in branchConfiguration.IsSourceBranchFor) - { - var targetBranchConfig = configuration.Branches[targetBranchName]; - targetBranchConfig.SourceBranches ??= new HashSet(); - targetBranchConfig.SourceBranches.Add(name); - } - } - - private static void ValidateConfiguration(GitVersionConfiguration configuration) - { - foreach (var (name, branchConfiguration) in configuration.Branches) - { - var regex = branchConfiguration.Regex; - var helpUrl = $"{System.Environment.NewLine}See https://gitversion.net/docs/reference/configuration for more info"; - - if (regex == null) - { - throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'regex'{helpUrl}"); - } - - var sourceBranches = branchConfiguration.SourceBranches; - if (sourceBranches == null) - { - throw new ConfigurationException($"Branch configuration '{name}' is missing required configuration 'source-branches'{helpUrl}"); - } - - var missingSourceBranches = sourceBranches.Where(sb => !configuration.Branches.ContainsKey(sb)).ToArray(); - if (missingSourceBranches.Any()) - throw new ConfigurationException($"Branch configuration '{name}' defines these 'source-branches' that are not configured: '[{string.Join(",", missingSourceBranches)}]'{helpUrl}"); - } - } - - private static GitVersionConfiguration CreateDefaultConfiguration() - { - var configuration = new GitVersionConfiguration - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, - AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - LabelPrefix = GitVersionConfiguration.DefaultLabelPrefix, - VersioningMode = VersioningMode.ContinuousDelivery, - ContinuousDeploymentFallbackLabel = "ci", - MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern, - MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern, - PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, - NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, - CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, - CommitDateFormat = "yyyy-MM-dd", - UpdateBuildNumber = true, - SemanticVersionFormat = SemanticVersionFormat.Strict, - LabelPreReleaseWeight = DefaultLabelPreReleaseWeight, - Increment = IncrementStrategy.Inherit - }; - - AddBranchConfig(GitVersionConfiguration.DevelopBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Minor, - Regex = GitVersionConfiguration.DevelopBranchRegex, - SourceBranches = new HashSet(), - Label = "alpha", - PreventIncrementOfMergedBranchVersion = false, - TrackMergeTarget = true, - TracksReleaseBranches = true, - IsMainline = false, - IsReleaseBranch = false, - PreReleaseWeight = 0 - }); - - AddBranchConfig(GitVersionConfiguration.MainBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Patch, - Regex = GitVersionConfiguration.MainBranchRegex, - SourceBranches = new HashSet { - GitVersionConfiguration.DevelopBranchKey, - GitVersionConfiguration.ReleaseBranchKey - }, - Label = string.Empty, - PreventIncrementOfMergedBranchVersion = true, - TrackMergeTarget = false, - TracksReleaseBranches = false, - IsMainline = true, - IsReleaseBranch = false, - PreReleaseWeight = 55000 - }); - - AddBranchConfig(GitVersionConfiguration.ReleaseBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.None, - Regex = GitVersionConfiguration.ReleaseBranchRegex, - SourceBranches = new HashSet { - GitVersionConfiguration.DevelopBranchKey, - GitVersionConfiguration.MainBranchKey, - GitVersionConfiguration.SupportBranchKey, - GitVersionConfiguration.ReleaseBranchKey - }, - Label = "beta", - PreventIncrementOfMergedBranchVersion = true, - TrackMergeTarget = false, - TracksReleaseBranches = false, - IsMainline = false, - IsReleaseBranch = true, - PreReleaseWeight = 30000 - }); - - AddBranchConfig(GitVersionConfiguration.FeatureBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Inherit, - Regex = GitVersionConfiguration.FeatureBranchRegex, - SourceBranches = new HashSet { - GitVersionConfiguration.DevelopBranchKey, - GitVersionConfiguration.MainBranchKey, - GitVersionConfiguration.ReleaseBranchKey, - GitVersionConfiguration.FeatureBranchKey, - GitVersionConfiguration.SupportBranchKey, - GitVersionConfiguration.HotfixBranchKey - }, - Label = "{BranchName}", - PreReleaseWeight = 30000 - }); - - AddBranchConfig(GitVersionConfiguration.PullRequestBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Inherit, - Regex = GitVersionConfiguration.PullRequestRegex, - SourceBranches = new HashSet { - GitVersionConfiguration.DevelopBranchKey, - GitVersionConfiguration.MainBranchKey, - GitVersionConfiguration.ReleaseBranchKey, - GitVersionConfiguration.FeatureBranchKey, - GitVersionConfiguration.SupportBranchKey, - GitVersionConfiguration.HotfixBranchKey - }, - Label = "PullRequest", - LabelNumberPattern = @"[/-](?\d+)", - PreReleaseWeight = 30000 - }); - - AddBranchConfig(GitVersionConfiguration.HotfixBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Inherit, - Regex = GitVersionConfiguration.HotfixBranchRegex, - SourceBranches = new HashSet { - GitVersionConfiguration.ReleaseBranchKey, - GitVersionConfiguration.MainBranchKey, - GitVersionConfiguration.SupportBranchKey, - GitVersionConfiguration.HotfixBranchKey - }, - Label = "beta", - PreReleaseWeight = 30000 - }); - - AddBranchConfig(GitVersionConfiguration.SupportBranchKey, - new BranchConfiguration - { - Increment = IncrementStrategy.Patch, - Regex = GitVersionConfiguration.SupportBranchRegex, - SourceBranches = new HashSet { GitVersionConfiguration.MainBranchKey }, - Label = string.Empty, - PreventIncrementOfMergedBranchVersion = true, - TrackMergeTarget = false, - TracksReleaseBranches = false, - IsMainline = true, - IsReleaseBranch = false, - PreReleaseWeight = 55000 - }); - - return configuration; - - void AddBranchConfig(string name, BranchConfiguration branchConfiguration) - { - branchConfiguration.Name = name; - configuration.Branches[name] = branchConfiguration; - } - } -} diff --git a/src/GitVersion.Core.Tests/Helpers/TestConfigurationBuilderBase.cs b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs similarity index 63% rename from src/GitVersion.Core.Tests/Helpers/TestConfigurationBuilderBase.cs rename to src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs index 0f79ecc28b..e9baff5742 100644 --- a/src/GitVersion.Core.Tests/Helpers/TestConfigurationBuilderBase.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs @@ -1,36 +1,46 @@ -using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.VersionCalculation; -namespace GitVersion.Core.Tests.Helpers; +namespace GitVersion.Configuration; -internal abstract class TestConfigurationBuilderBase - where TConfigurationBuilder : TestConfigurationBuilderBase +internal abstract class ConfigurationBuilderBase + where TConfigurationBuilder : ConfigurationBuilderBase { private AssemblyVersioningScheme? assemblyVersioningScheme; private AssemblyFileVersioningScheme? assemblyFileVersioningScheme; private string? assemblyInformationalFormat; private string? assemblyVersioningFormat; private string? assemblyFileVersioningFormat; - private VersioningMode? versioningMode; - private string? tagPrefix; - private string? continuousDeploymentFallbackTag; + private string? labelPrefix; private string? nextVersion; private string? majorVersionBumpMessage; private string? minorVersionBumpMessage; private string? patchVersionBumpMessage; private string? noBumpMessage; - private int? tagPreReleaseWeight; - private CommitMessageIncrementMode? commitMessageIncrementing; + private int? labelPreReleaseWeight; private IgnoreConfiguration ignore; - private IncrementStrategy? increment; private string? commitDateFormat; - private bool? updateBuildNumber; - private SemanticVersionFormat semanticVersionFormat = SemanticVersionFormat.Strict; + private bool updateBuildNumber; + private SemanticVersionFormat semanticVersionFormat; private Dictionary? mergeMessageFormats; - protected readonly Dictionary branchConfigurationBuilders = new(); - - protected TestConfigurationBuilderBase() + private readonly List> overrides = new(); + private readonly Dictionary branchConfigurationBuilders = new(); + private VersioningMode? versioningMode; + private string? label; + private IncrementStrategy? increment; + private bool? preventIncrementOfMergedBranchVersion; + private string? labelNumberPattern; + private bool? trackMergeTarget; + private CommitMessageIncrementMode? commitMessageIncrementing; + private string? regex; + private HashSet? sourceBranches; + private HashSet? isSourceBranchFor; + private bool? tracksReleaseBranches; + private bool? isReleaseBranch; + private bool? isMainline; + private int? preReleaseWeight; + + protected ConfigurationBuilderBase() { if (GetType() != typeof(TConfigurationBuilder)) { @@ -68,27 +78,9 @@ public virtual TConfigurationBuilder WithAssemblyFileVersioningFormat(string? va return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithoutVersioningMode() - { - this.versioningMode = null; - return (TConfigurationBuilder)this; - } - - public virtual TConfigurationBuilder WithVersioningMode(VersioningMode value) - { - this.versioningMode = value; - return (TConfigurationBuilder)this; - } - - public virtual TConfigurationBuilder WithTagPrefix(string? value) - { - this.tagPrefix = value; - return (TConfigurationBuilder)this; - } - - public virtual TConfigurationBuilder WithContinuousDeploymentFallbackTag(string? value) + public virtual TConfigurationBuilder WithLabelPrefix(string? value) { - this.continuousDeploymentFallbackTag = value; + this.labelPrefix = value; return (TConfigurationBuilder)this; } @@ -122,15 +114,9 @@ public virtual TConfigurationBuilder WithNoBumpMessage(string? value) return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithTagPreReleaseWeight(int? value) + public virtual TConfigurationBuilder WithLabelPreReleaseWeight(int? value) { - this.tagPreReleaseWeight = value; - return (TConfigurationBuilder)this; - } - - public virtual TConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value) - { - this.commitMessageIncrementing = value; + this.labelPreReleaseWeight = value; return (TConfigurationBuilder)this; } @@ -140,19 +126,13 @@ public virtual TConfigurationBuilder WithIgnoreConfiguration(IgnoreConfiguration return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithIncrement(IncrementStrategy? value) - { - this.increment = value; - return (TConfigurationBuilder)this; - } - public virtual TConfigurationBuilder WithCommitDateFormat(string? value) { this.commitDateFormat = value; return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithUpdateBuildNumber(bool? value) + public virtual TConfigurationBuilder WithUpdateBuildNumber(bool value) { this.updateBuildNumber = value; return (TConfigurationBuilder)this; @@ -170,21 +150,123 @@ public virtual TConfigurationBuilder WithMergeMessageFormats(Dictionary TestBranchConfigurationBuilder.New); + this.branchConfigurationBuilders.Clear(); + return (TConfigurationBuilder)this; + } + + public virtual BranchConfigurationBuilder WithBranch(string value) + { + var result = this.branchConfigurationBuilders.GetOrAdd(value, () => BranchConfigurationBuilder.New); result.WithName(value); return result; } - public virtual TConfigurationBuilder WithBranch(string value, Action action) + public virtual TConfigurationBuilder WithBranch(string value, Action action) { - var result = this.branchConfigurationBuilders.GetOrAdd(value, () => TestBranchConfigurationBuilder.New); + var result = this.branchConfigurationBuilders.GetOrAdd(value, () => BranchConfigurationBuilder.New); result.WithName(value); action(result); return (TConfigurationBuilder)this; } + public virtual TConfigurationBuilder WithVersioningMode(VersioningMode? value) + { + this.versioningMode = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithLabel(string? value) + { + this.label = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithIncrement(IncrementStrategy? value) + { + this.increment = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(bool? value) + { + this.preventIncrementOfMergedBranchVersion = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithLabelNumberPattern(string? value) + { + this.labelNumberPattern = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithTrackMergeTarget(bool? value) + { + this.trackMergeTarget = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value) + { + this.commitMessageIncrementing = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithRegex(string? value) + { + this.regex = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithSourceBranches(IEnumerable? values) + { + WithSourceBranches(values?.ToArray()); + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithSourceBranches(params string[]? values) + { + this.sourceBranches = values == null ? null : new HashSet(values); + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithIsSourceBranchFor(IEnumerable? values) + { + WithIsSourceBranchFor(values?.ToArray()); + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithIsSourceBranchFor(params string[]? values) + { + this.isSourceBranchFor = values == null ? null : new HashSet(values); + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithTracksReleaseBranches(bool? value) + { + this.tracksReleaseBranches = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithIsReleaseBranch(bool? value) + { + this.isReleaseBranch = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithIsMainline(bool? value) + { + this.isMainline = value; + return (TConfigurationBuilder)this; + } + + public virtual TConfigurationBuilder WithPreReleaseWeight(int? value) + { + this.preReleaseWeight = value; + return (TConfigurationBuilder)this; + } + public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration value) { WithAssemblyVersioningScheme(value.AssemblyVersioningScheme); @@ -192,25 +274,14 @@ public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration v WithAssemblyInformationalFormat(value.AssemblyInformationalFormat); WithAssemblyVersioningFormat(value.AssemblyVersioningFormat); WithAssemblyFileVersioningFormat(value.AssemblyFileVersioningFormat); - if (value.VersioningMode.HasValue) - { - WithVersioningMode(value.VersioningMode.Value); - } - else - { - WithoutVersioningMode(); - } - WithTagPrefix(value.LabelPrefix); - WithContinuousDeploymentFallbackTag(value.ContinuousDeploymentFallbackLabel); + WithLabelPrefix(value.LabelPrefix); WithNextVersion(value.NextVersion); WithMajorVersionBumpMessage(value.MajorVersionBumpMessage); WithMinorVersionBumpMessage(value.MinorVersionBumpMessage); WithPatchVersionBumpMessage(value.PatchVersionBumpMessage); WithNoBumpMessage(value.NoBumpMessage); - WithTagPreReleaseWeight(value.LabelPreReleaseWeight); - WithCommitMessageIncrementing(value.CommitMessageIncrementing); + WithLabelPreReleaseWeight(value.LabelPreReleaseWeight); WithIgnoreConfiguration(value.Ignore); - WithIncrement(value.Increment); WithCommitDateFormat(value.CommitDateFormat); WithUpdateBuildNumber(value.UpdateBuildNumber); WithSemanticVersionFormat(value.SemanticVersionFormat); @@ -219,6 +290,29 @@ public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration v { WithBranch(name).WithConfiguration(branchConfiguration); } + WithVersioningMode(value.VersioningMode); + WithLabel(value.Label); + WithIncrement(value.Increment); + WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion); + WithLabelNumberPattern(value.LabelNumberPattern); + WithTrackMergeTarget(value.TrackMergeTarget); + WithCommitMessageIncrementing(value.CommitMessageIncrementing); + WithRegex(value.Regex); + WithTracksReleaseBranches(value.TracksReleaseBranches); + WithIsReleaseBranch(value.IsReleaseBranch); + WithIsMainline(value.IsMainline); + WithPreReleaseWeight(value.PreReleaseWeight); + WithSourceBranches(value.SourceBranches); + WithIsSourceBranchFor(value.IsSourceBranchFor); + return (TConfigurationBuilder)this; + } + + public TConfigurationBuilder AddOverride(IReadOnlyDictionary value) + { + if (value.Any()) + { + this.overrides.Add(value); + } return (TConfigurationBuilder)this; } @@ -231,33 +325,54 @@ public virtual GitVersionConfiguration Build() AssemblyInformationalFormat = this.assemblyInformationalFormat, AssemblyVersioningFormat = this.assemblyVersioningFormat, AssemblyFileVersioningFormat = this.assemblyFileVersioningFormat, - VersioningMode = this.versioningMode, - LabelPrefix = this.tagPrefix, - ContinuousDeploymentFallbackLabel = this.continuousDeploymentFallbackTag, + LabelPrefix = this.labelPrefix, NextVersion = this.nextVersion, MajorVersionBumpMessage = this.majorVersionBumpMessage, MinorVersionBumpMessage = this.minorVersionBumpMessage, PatchVersionBumpMessage = this.patchVersionBumpMessage, NoBumpMessage = this.noBumpMessage, - LabelPreReleaseWeight = this.tagPreReleaseWeight, - CommitMessageIncrementing = this.commitMessageIncrementing, + LabelPreReleaseWeight = this.labelPreReleaseWeight, Ignore = this.ignore, - Increment = this.increment, CommitDateFormat = this.commitDateFormat, UpdateBuildNumber = this.updateBuildNumber, SemanticVersionFormat = this.semanticVersionFormat, - MergeMessageFormats = this.mergeMessageFormats ?? new() + MergeMessageFormats = this.mergeMessageFormats ?? new(), + VersioningMode = this.versioningMode, + Label = this.label, + Increment = this.increment, + Regex = this.regex, + TracksReleaseBranches = this.tracksReleaseBranches, + TrackMergeTarget = this.trackMergeTarget, + CommitMessageIncrementing = this.commitMessageIncrementing, + IsMainline = this.isMainline, + IsReleaseBranch = this.isReleaseBranch, + LabelNumberPattern = this.labelNumberPattern, + PreventIncrementOfMergedBranchVersion = this.preventIncrementOfMergedBranchVersion, + PreReleaseWeight = this.preReleaseWeight, + SourceBranches = this.sourceBranches, + IsSourceBranchFor = this.isSourceBranchFor }; + Dictionary branches = new(); foreach (var (name, branchConfigurationBuilder) in this.branchConfigurationBuilders) { branches.Add(name, branchConfigurationBuilder.Build()); } + configuration.Branches = branches; + + if (this.overrides.Any()) + { + ConfigurationHelper configurationHelper = new(configuration); + foreach (var item in this.overrides) + { + configurationHelper.Override(item); + } + configuration = configurationHelper.Configuration; + } FinalizeConfiguration(configuration); ValidateConfiguration(configuration); - configuration.Branches = branches; return configuration; } @@ -310,8 +425,8 @@ private static void ValidateConfiguration(GitVersionConfiguration configuration) public record BranchMetaData { - public string Name { get; init; } + public string Name { get; set; } - public string RegexPattern { get; init; } + public string RegexPattern { get; set; } } } diff --git a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs index a323214c17..a7b0bcbdde 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs @@ -1,6 +1,7 @@ using System.Text.RegularExpressions; using GitVersion.Extensions; using GitVersion.Logging; +using GitVersion.VersionCalculation; namespace GitVersion.Configuration; @@ -11,41 +12,60 @@ public static BranchConfiguration GetBranchConfiguration(this GitVersionConfigur public static BranchConfiguration GetBranchConfiguration(this GitVersionConfiguration configuration, string branchName) { - var branchConfiguration = ForBranch(configuration, branchName); - if (branchConfiguration is null) + var branchConfiguration = GetBranchConfigurations(configuration, branchName).FirstOrDefault(); + branchConfiguration ??= new() { - branchConfiguration = GetUnknownBranchConfiguration(configuration); - branchConfiguration.Name = branchName; + Name = branchName, + Regex = string.Empty, + Label = "{BranchName}", + 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; } - // TODO: Please make the unknown settings also configurable in the yaml. - public static BranchConfiguration GetUnknownBranchConfiguration(this GitVersionConfiguration configuration) => new() + private static IEnumerable GetBranchConfigurations(GitVersionConfiguration configuration, string branchName) { - Name = "Unknown", - Regex = "", - Label = "{BranchName}", - VersioningMode = configuration.VersioningMode, - Increment = IncrementStrategy.Inherit - }; + BranchConfiguration? unknownBranchConfiguration = null; + foreach (var item in configuration.Branches.Values.Where(b => b.Regex != null)) + { + if (item.Regex != null && Regex.IsMatch(branchName, item.Regex, RegexOptions.IgnoreCase)) + { + if (item.Name == "unknown") + { + unknownBranchConfiguration = item; + } + else + { + yield return item; + } + } + } + if (unknownBranchConfiguration != null) yield return unknownBranchConfiguration; + } - // TODO: Please make the fallback settings also configurable in the yaml. public static BranchConfiguration GetFallbackBranchConfiguration(this GitVersionConfiguration configuration) { - var result = new BranchConfiguration() - { - Name = "Fallback", - Regex = "", - Label = "{BranchName}", - VersioningMode = configuration.VersioningMode, - Increment = configuration.Increment, - PreventIncrementOfMergedBranchVersion = false, - TrackMergeTarget = false, - TracksReleaseBranches = false, - IsReleaseBranch = false, - IsMainline = false - }; + BranchConfiguration result = new(configuration); + result.Name ??= "fallback"; + result.Regex ??= ""; + result.Label ??= "{BranchName}"; + result.VersioningMode ??= VersioningMode.ContinuousDelivery; + result.PreventIncrementOfMergedBranchVersion ??= false; + result.TrackMergeTarget ??= false; + result.TracksReleaseBranches ??= false; + result.IsReleaseBranch ??= false; + result.IsMainline ??= false; + result.CommitMessageIncrementing ??= CommitMessageIncrementMode.Enabled; if (result.Increment == IncrementStrategy.Inherit) { result.Increment = IncrementStrategy.None; @@ -59,26 +79,7 @@ public static BranchConfiguration GetFallbackBranchConfiguration(this GitVersion .Where(b => b.Value.Regex != null && Regex.IsMatch(branchName, b.Value.Regex, RegexOptions.IgnoreCase)) .ToArray(); - try - { - return matches - .Select(kvp => kvp.Value) - .SingleOrDefault(); - } - catch (InvalidOperationException) - { - var matchingConfigs = string.Concat(matches.Select(m => $"{System.Environment.NewLine} - {m.Key}")); - var picked = matches - .Select(kvp => kvp.Value) - .First(); - - // TODO check how to log this - Console.WriteLine( - $"Multiple branch configurations match the current branch branchName of '{branchName}'. " + - $"Using the first matching configuration, '{picked.Name}'. Matching configurations include:'{matchingConfigs}'"); - - return picked; - } + return matches.Select(kvp => kvp.Value).FirstOrDefault(); } public static bool IsReleaseBranch(this GitVersionConfiguration configuration, string branchName) => configuration.GetBranchConfiguration(branchName).IsReleaseBranch ?? false; diff --git a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs index 0570e16262..31ce9adc5e 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs @@ -55,6 +55,21 @@ public GitVersionConfiguration ReadConfig(string workingDirectory) return new GitVersionConfiguration(); } + public IReadOnlyDictionary? ReadOverrideConfiguration(string? workingDirectory) + { + var configFilePath = GetConfigFilePath(workingDirectory); + + Dictionary? configuration = null; + if (configFilePath != null && this.fileSystem.Exists(configFilePath)) + { + var readAllText = this.fileSystem.ReadAllText(configFilePath); + + configuration = ConfigurationSerializer.Deserialize>(readAllText); + } + + return configuration; + } + public void Verify(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo) { if (!gitVersionOptions.RepositoryInfo.TargetUrl.IsNullOrWhiteSpace()) diff --git a/src/GitVersion.Core/Configuration/ConfigurationHelper.cs b/src/GitVersion.Core/Configuration/ConfigurationHelper.cs new file mode 100644 index 0000000000..e129f61e00 --- /dev/null +++ b/src/GitVersion.Core/Configuration/ConfigurationHelper.cs @@ -0,0 +1,104 @@ +using GitVersion.Extensions; + +namespace GitVersion.Configuration; + +internal class ConfigurationHelper +{ + public string Yaml + { + get + { + if (this.yaml == null) + { + if (this.dictionary == null) + { + this.yaml = ConfigurationSerializer.Serialize(this.configuration!); + } + else + { + this.yaml = ConfigurationSerializer.Serialize(this.dictionary); + } + } + return this.yaml; + } + } + private string? yaml; + + public IReadOnlyDictionary Dictionary + { + get + { + if (this.dictionary == null) + { + this.yaml ??= ConfigurationSerializer.Serialize(this.configuration!); + this.dictionary = ConfigurationSerializer.Deserialize>(this.yaml!); + } + return this.dictionary; + } + } + private IReadOnlyDictionary? dictionary; + + public GitVersionConfiguration Configuration => this.configuration ??= ConfigurationSerializer.Deserialize(Yaml); + private GitVersionConfiguration? configuration; + + public ConfigurationHelper(string yaml) => this.yaml = yaml.NotNull(); + + public ConfigurationHelper(IReadOnlyDictionary dictionary) => this.dictionary = dictionary.NotNull(); + + public ConfigurationHelper(GitVersionConfiguration configuration) => this.configuration = configuration.NotNull(); + + public void Override(IReadOnlyDictionary value) + { + value.NotNull(); + + if (value.Any()) + { + var dictionary = Dictionary.ToDictionary(element => element.Key, element => element.Value); + Merge(dictionary, value); + this.dictionary = dictionary; + this.yaml = null; + this.configuration = null; + } + } + + private static void Merge(IDictionary dictionary, IReadOnlyDictionary anotherDictionary) + { + foreach (var item in dictionary) + { + if (item.Value is IDictionary anotherDictionaryValue) + { + if (anotherDictionary.TryGetValue(item.Key, out var value) && value is IReadOnlyDictionary dictionaryValue) + { + Merge(anotherDictionaryValue, dictionaryValue); + } + } + else if (item.Value is null || item.Value is string || item.Value is IList) + { + if (anotherDictionary.TryGetValue(item.Key, out var value)) + { + dictionary[item.Key] = value; + } + } + } + + foreach (var item in anotherDictionary) + { + if (item.Value is IReadOnlyDictionary dictionaryValue) + { + if (!dictionary.ContainsKey(item.Key)) + { + Dictionary anotherDictionaryValue = new(); + Merge(anotherDictionaryValue, dictionaryValue); + dictionary.Add(item.Key, anotherDictionaryValue); + } + } + else if (item.Value is null || item.Value is string || item.Value is IList) + { + if (!dictionary.ContainsKey(item.Key)) + { + dictionary.Add(item.Key, item.Value); + } + } + } + } +} diff --git a/src/GitVersion.Core/Configuration/ConfigurationProvider.cs b/src/GitVersion.Core/Configuration/ConfigurationProvider.cs index e22792318a..f029f0efe9 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationProvider.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationProvider.cs @@ -2,6 +2,7 @@ using GitVersion.Extensions; using GitVersion.Logging; using Microsoft.Extensions.Options; +using YamlDotNet.Core; namespace GitVersion.Configuration; @@ -23,7 +24,7 @@ public ConfigurationProvider(IFileSystem fileSystem, ILog log, IConfigurationFil this.configInitWizard = configInitWizard.NotNull(); } - public GitVersionConfiguration Provide(GitVersionConfiguration? overrideConfiguration) + public GitVersionConfiguration Provide(IReadOnlyDictionary? overrideConfiguration) { var gitVersionOptions = this.options.Value; var workingDirectory = gitVersionOptions.WorkingDirectory; @@ -48,17 +49,28 @@ public void Init(string workingDirectory) stream.Flush(); } - internal GitVersionConfiguration ProvideInternal(string? workingDirectory, GitVersionConfiguration? overrideConfiguration = null) + internal GitVersionConfiguration ProvideInternal( + string? workingDirectory, IReadOnlyDictionary? overrideConfiguration = null) { - var configurationBuilder = new ConfigurationBuilder(); + var overrideConfigurationFromFile = this.configFileLocator.ReadOverrideConfiguration(workingDirectory); - if (workingDirectory != null) - configurationBuilder = configurationBuilder.Add(this.configFileLocator.ReadConfig(workingDirectory)); - - if (overrideConfiguration != null) - configurationBuilder.Add(overrideConfiguration); + var configurationBuilder = GitFlowConfigurationBuilder.New; + foreach (var item in new[] { overrideConfigurationFromFile, overrideConfiguration }) + { + if (item != null) configurationBuilder.AddOverride(item); + } - return configurationBuilder.Build(); + try + { + return configurationBuilder.Build(); + } + catch (YamlException exception) + { + throw new WarningException( + $"Could not build the configuration instance because following exception occurred: '{exception.Message}' " + + $"Please ensure that the /overrideconfig parameters are correct and the configuration file is in the correct format." + ); + } } private static string? ReadGitDirFromFile(string fileName) diff --git a/src/GitVersion.Core/Configuration/ConfigurationSerializer.cs b/src/GitVersion.Core/Configuration/ConfigurationSerializer.cs index b916f60ab5..3670e25b52 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationSerializer.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationSerializer.cs @@ -3,23 +3,25 @@ namespace GitVersion.Configuration; -public class ConfigurationSerializer +public static class ConfigurationSerializer { + private static IDeserializer Deserializer + => new DeserializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build(); + + public static T Deserialize(string input) => Deserializer.Deserialize(input); + + public static string Serialize(object graph) => Serializer.Serialize(graph); + + private static ISerializer Serializer + => new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .WithNamingConvention(HyphenatedNamingConvention.Instance).Build(); + public static GitVersionConfiguration Read(TextReader reader) { - var deserializer = new DeserializerBuilder() - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .Build(); - var configuration = deserializer.Deserialize(reader); + var configuration = Deserializer.Deserialize(reader); return configuration ?? new GitVersionConfiguration(); } public static void Write(GitVersionConfiguration configuration, TextWriter writer) - { - var serializer = new SerializerBuilder() - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults) - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .Build(); - serializer.Serialize(writer, configuration); - } + => Serializer.Serialize(writer, configuration); } diff --git a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index 96b3168b40..39b09280c6 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -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 (!configuration.CommitMessageIncrementing.HasValue) + if (!currentBranchConfig.CommitMessageIncrementing.HasValue) throw new Exception("Configuration value for 'CommitMessageIncrementing' has no value. (this should not happen, please report an issue)"); if (!configuration.LabelPreReleaseWeight.HasValue) @@ -47,19 +47,18 @@ public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfi BranchPrefixToTrim = currentBranchConfig.Regex; PreventIncrementOfMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion ?? false; LabelNumberPattern = currentBranchConfig.LabelNumberPattern; - ContinuousDeploymentFallbackLabel = configuration.ContinuousDeploymentFallbackLabel; TrackMergeTarget = currentBranchConfig.TrackMergeTarget ?? false; MajorVersionBumpMessage = configuration.MajorVersionBumpMessage; MinorVersionBumpMessage = configuration.MinorVersionBumpMessage; PatchVersionBumpMessage = configuration.PatchVersionBumpMessage; NoBumpMessage = configuration.NoBumpMessage; - CommitMessageIncrementing = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; + CommitMessageIncrementing = currentBranchConfig.CommitMessageIncrementing.Value; VersionFilters = configuration.Ignore.ToFilters(); TracksReleaseBranches = currentBranchConfig.TracksReleaseBranches ?? false; IsReleaseBranch = currentBranchConfig.IsReleaseBranch ?? false; IsMainline = currentBranchConfig.IsMainline ?? false; CommitDateFormat = configuration.CommitDateFormat; - UpdateBuildNumber = configuration.UpdateBuildNumber ?? true; + UpdateBuildNumber = configuration.UpdateBuildNumber; SemanticVersionFormat = configuration.SemanticVersionFormat; PreReleaseWeight = currentBranchConfig.PreReleaseWeight ?? 0; LabelPreReleaseWeight = configuration.LabelPreReleaseWeight.Value; @@ -78,7 +77,6 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche string? branchPrefixToTrim, bool preventIncrementOfMergedBranchVersion, string? labelNumberPattern, - string? continuousDeploymentFallbackLabel, bool trackMergeTarget, string? majorVersionBumpMessage, string? minorVersionBumpMessage, @@ -108,7 +106,6 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche BranchPrefixToTrim = branchPrefixToTrim; PreventIncrementOfMergedBranchVersion = preventIncrementOfMergedBranchVersion; LabelNumberPattern = labelNumberPattern; - ContinuousDeploymentFallbackLabel = continuousDeploymentFallbackLabel; TrackMergeTarget = trackMergeTarget; MajorVersionBumpMessage = majorVersionBumpMessage; MinorVersionBumpMessage = minorVersionBumpMessage; @@ -156,8 +153,6 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche public string? LabelNumberPattern { get; } - public string? ContinuousDeploymentFallbackLabel { get; } - public bool TrackMergeTarget { get; } public string? MajorVersionBumpMessage { get; } diff --git a/src/GitVersion.Core/Configuration/EmptyConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/EmptyConfigurationBuilder.cs new file mode 100644 index 0000000000..3dd9b34290 --- /dev/null +++ b/src/GitVersion.Core/Configuration/EmptyConfigurationBuilder.cs @@ -0,0 +1,10 @@ +namespace GitVersion.Configuration; + +internal sealed class EmptyConfigurationBuilder : ConfigurationBuilderBase +{ + public static EmptyConfigurationBuilder New => new(); + + private EmptyConfigurationBuilder() + { + } +} diff --git a/src/GitVersion.Core.Tests/Helpers/GitFlowConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs similarity index 78% rename from src/GitVersion.Core.Tests/Helpers/GitFlowConfigurationBuilder.cs rename to src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs index 7b125d4a00..204afbbc0b 100644 --- a/src/GitVersion.Core.Tests/Helpers/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs @@ -1,10 +1,9 @@ -using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.VersionCalculation; -namespace GitVersion.Core.Tests.Helpers; +namespace GitVersion.Configuration; -internal sealed class GitFlowConfigurationBuilder : TestConfigurationBuilderBase +internal sealed class GitFlowConfigurationBuilder : ConfigurationBuilderBase { public static GitFlowConfigurationBuilder New => new(); @@ -12,28 +11,34 @@ private GitFlowConfigurationBuilder() { WithConfiguration(new() { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - LabelPrefix = GitVersionConfiguration.DefaultLabelPrefix, - VersioningMode = VersioningMode.ContinuousDelivery, - ContinuousDeploymentFallbackLabel = "ci", + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, + CommitDateFormat = "yyyy-MM-dd", MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern, MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern, - PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, - CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, - CommitDateFormat = "yyyy-MM-dd", - UpdateBuildNumber = true, + PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, SemanticVersionFormat = SemanticVersionFormat.Strict, + LabelPrefix = GitVersionConfiguration.DefaultLabelPrefix, LabelPreReleaseWeight = 60000, - Increment = IncrementStrategy.Inherit + UpdateBuildNumber = true, + VersioningMode = VersioningMode.ContinuousDelivery, + Regex = string.Empty, + Label = "{BranchName}", + Increment = IncrementStrategy.Inherit, + CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, + PreventIncrementOfMergedBranchVersion = false, + TrackMergeTarget = false, + TracksReleaseBranches = false, + IsReleaseBranch = false, + IsMainline = false }); WithBranch(DevelopBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDeployment, Increment = IncrementStrategy.Minor, Regex = DevelopBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDeployment, SourceBranches = new HashSet(), Label = "alpha", PreventIncrementOfMergedBranchVersion = false, @@ -46,7 +51,6 @@ private GitFlowConfigurationBuilder() WithBranch(MainBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Patch, Regex = MainBranch.RegexPattern, SourceBranches = new HashSet { @@ -64,7 +68,6 @@ private GitFlowConfigurationBuilder() WithBranch(ReleaseBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.None, Regex = ReleaseBranch.RegexPattern, SourceBranches = new HashSet { @@ -84,9 +87,9 @@ private GitFlowConfigurationBuilder() WithBranch(FeatureBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Inherit, Regex = FeatureBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { DevelopBranch.Name, MainBranch.Name, @@ -101,9 +104,9 @@ private GitFlowConfigurationBuilder() WithBranch(PullRequestBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Inherit, Regex = PullRequestBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { DevelopBranch.Name, MainBranch.Name, @@ -119,9 +122,9 @@ private GitFlowConfigurationBuilder() WithBranch(HotfixBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Inherit, Regex = HotfixBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { ReleaseBranch.Name, MainBranch.Name, @@ -134,7 +137,6 @@ private GitFlowConfigurationBuilder() WithBranch(SupportBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Patch, Regex = SupportBranch.RegexPattern, SourceBranches = new HashSet { MainBranch.Name }, @@ -146,47 +148,70 @@ private GitFlowConfigurationBuilder() IsReleaseBranch = false, PreReleaseWeight = 55000 }); + + WithBranch(UnknownBranch.Name).WithConfiguration(new() + { + Regex = UnknownBranch.RegexPattern, + Label = "{BranchName}", + VersioningMode = VersioningMode.ContinuousDelivery, + Increment = IncrementStrategy.Inherit, + SourceBranches = new HashSet { + MainBranch.Name, + DevelopBranch.Name, + ReleaseBranch.Name, + FeatureBranch.Name, + PullRequestBranch.Name, + HotfixBranch.Name, + SupportBranch.Name + } + }); } - public static BranchMetaData MainBranch = new() + public static readonly BranchMetaData MainBranch = new() { Name = "main", RegexPattern = "^master$|^main$" }; - public static BranchMetaData DevelopBranch = new() + public static readonly BranchMetaData DevelopBranch = new() { Name = "develop", RegexPattern = "^dev(elop)?(ment)?$" }; - public static BranchMetaData ReleaseBranch = new() + public static readonly BranchMetaData ReleaseBranch = new() { Name = "release", RegexPattern = "^releases?[/-]" }; - public static BranchMetaData FeatureBranch = new() + public static readonly BranchMetaData FeatureBranch = new() { Name = "feature", RegexPattern = "^features?[/-]" }; - public static BranchMetaData PullRequestBranch = new() + public static readonly BranchMetaData PullRequestBranch = new() { Name = "pull-request", RegexPattern = @"^(pull|pull\-requests|pr)[/-]" }; - public static BranchMetaData HotfixBranch = new() + public static readonly BranchMetaData HotfixBranch = new() { Name = "hotfix", RegexPattern = "^hotfix(es)?[/-]" }; - public static BranchMetaData SupportBranch = new() + public static readonly BranchMetaData SupportBranch = new() { Name = "support", RegexPattern = "^support[/-]" }; + + public static readonly BranchMetaData UnknownBranch = new() + { + Name = "unknown", + RegexPattern = ".*" + }; } diff --git a/src/GitVersion.Core.Tests/Helpers/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs similarity index 74% rename from src/GitVersion.Core.Tests/Helpers/GitHubFlowConfigurationBuilder.cs rename to src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs index b67b21a67b..041cd080c2 100644 --- a/src/GitVersion.Core.Tests/Helpers/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Core/Configuration/GitHubFlowConfigurationBuilder.cs @@ -1,10 +1,9 @@ -using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.VersionCalculation; -namespace GitVersion.Core.Tests.Helpers; +namespace GitVersion.Configuration; -internal sealed class GitHubFlowConfigurationBuilder : TestConfigurationBuilderBase +internal sealed class GitHubFlowConfigurationBuilder : ConfigurationBuilderBase { public static GitHubFlowConfigurationBuilder New => new(); @@ -12,26 +11,31 @@ private GitHubFlowConfigurationBuilder() { WithConfiguration(new() { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - LabelPrefix = GitVersionConfiguration.DefaultLabelPrefix, - VersioningMode = VersioningMode.ContinuousDelivery, - ContinuousDeploymentFallbackLabel = "ci", + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, + CommitDateFormat = "yyyy-MM-dd", MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern, MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern, - PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, - CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, - CommitDateFormat = "yyyy-MM-dd", - UpdateBuildNumber = true, + PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, SemanticVersionFormat = SemanticVersionFormat.Strict, + LabelPrefix = GitVersionConfiguration.DefaultLabelPrefix, LabelPreReleaseWeight = 60000, - Increment = IncrementStrategy.Inherit + UpdateBuildNumber = true, + VersioningMode = VersioningMode.ContinuousDelivery, + Regex = string.Empty, + Label = "{BranchName}", + Increment = IncrementStrategy.Inherit, + CommitMessageIncrementing = CommitMessageIncrementMode.Enabled, + PreventIncrementOfMergedBranchVersion = false, + TrackMergeTarget = false, + TracksReleaseBranches = false, + IsReleaseBranch = false, + IsMainline = false }); WithBranch(MainBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Patch, Regex = MainBranch.RegexPattern, SourceBranches = new HashSet { @@ -48,7 +52,6 @@ private GitHubFlowConfigurationBuilder() WithBranch(ReleaseBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.None, Regex = ReleaseBranch.RegexPattern, SourceBranches = new HashSet { @@ -66,9 +69,9 @@ private GitHubFlowConfigurationBuilder() WithBranch(FeatureBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Inherit, Regex = FeatureBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { MainBranch.Name, ReleaseBranch.Name, @@ -80,9 +83,9 @@ private GitHubFlowConfigurationBuilder() WithBranch(PullRequestBranch.Name).WithConfiguration(new() { - VersioningMode = VersioningMode.ContinuousDelivery, Increment = IncrementStrategy.Inherit, Regex = PullRequestBranch.RegexPattern, + VersioningMode = VersioningMode.ContinuousDelivery, SourceBranches = new HashSet { MainBranch.Name, ReleaseBranch.Name, @@ -92,29 +95,49 @@ private GitHubFlowConfigurationBuilder() LabelNumberPattern = @"[/-](?\d+)", PreReleaseWeight = 30000 }); + + WithBranch(UnknownBranch.Name).WithConfiguration(new() + { + Regex = UnknownBranch.RegexPattern, + Label = "{BranchName}", + VersioningMode = VersioningMode.ContinuousDelivery, + Increment = IncrementStrategy.Inherit, + SourceBranches = new HashSet { + MainBranch.Name, + ReleaseBranch.Name, + FeatureBranch.Name, + PullRequestBranch.Name + } + }); } - public static BranchMetaData MainBranch = new() + public static readonly BranchMetaData MainBranch = new() { Name = "main", RegexPattern = "^master$|^main$" }; - public static BranchMetaData ReleaseBranch = new() + public static readonly BranchMetaData ReleaseBranch = new() { Name = "release", RegexPattern = "^releases?[/-]" }; - public static BranchMetaData FeatureBranch = new() + public static readonly BranchMetaData FeatureBranch = new() { Name = "feature", RegexPattern = "^features?[/-]" }; - public static BranchMetaData PullRequestBranch = new() + public static readonly BranchMetaData PullRequestBranch = new() { Name = "pull-request", RegexPattern = @"^(pull|pull\-requests|pr)[/-]" }; + + public static readonly BranchMetaData UnknownBranch = new() + { + Name = "unknown", + RegexPattern = ".*" + }; } diff --git a/src/GitVersion.Core/Configuration/GitVersionConfiguration.cs b/src/GitVersion.Core/Configuration/GitVersionConfiguration.cs index 0dfa39cca9..433d9ecf7b 100644 --- a/src/GitVersion.Core/Configuration/GitVersionConfiguration.cs +++ b/src/GitVersion.Core/Configuration/GitVersionConfiguration.cs @@ -1,11 +1,10 @@ using System.Globalization; using GitVersion.Extensions; -using GitVersion.VersionCalculation; using YamlDotNet.Serialization; namespace GitVersion.Configuration; -public class GitVersionConfiguration +public class GitVersionConfiguration : BranchConfiguration { private string? nextVersion; @@ -30,15 +29,9 @@ public GitVersionConfiguration() [YamlMember(Alias = "assembly-file-versioning-format")] public string? AssemblyFileVersioningFormat { get; set; } - [YamlMember(Alias = "mode")] - public VersioningMode? VersioningMode { get; set; } - [YamlMember(Alias = "label-prefix")] public string? LabelPrefix { get; set; } - [YamlMember(Alias = "continuous-delivery-fallback-label")] - public string? ContinuousDeploymentFallbackLabel { get; set; } - [YamlMember(Alias = "next-version")] public string? NextVersion { @@ -64,18 +57,6 @@ public string? NextVersion [YamlMember(Alias = "label-pre-release-weight")] public int? LabelPreReleaseWeight { get; set; } - [YamlMember(Alias = "commit-message-incrementing")] - public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } - - [YamlMember(Alias = "branches")] - public Dictionary Branches { get; set; } - - [YamlMember(Alias = "ignore")] - public IgnoreConfiguration Ignore { get; set; } - - [YamlMember(Alias = "increment")] - public IncrementStrategy? Increment { get; set; } - [YamlMember(Alias = "commit-date-format")] public string? CommitDateFormat { get; set; } @@ -83,10 +64,16 @@ public string? NextVersion public Dictionary MergeMessageFormats { get; set; } = new(); [YamlMember(Alias = "update-build-number")] - public bool? UpdateBuildNumber { get; set; } + public bool UpdateBuildNumber { get; set; } = true; + + [YamlMember(Alias = "semantic-version-format")] + public SemanticVersionFormat SemanticVersionFormat { get; set; } + + [YamlMember(Alias = "branches")] + public Dictionary Branches { get; set; } - [YamlMember(Alias = "semver-format")] - public SemanticVersionFormat SemanticVersionFormat { get; set; } = SemanticVersionFormat.Strict; + [YamlMember(Alias = "ignore")] + public IgnoreConfiguration Ignore { get; set; } public override string ToString() { diff --git a/src/GitVersion.Core/Configuration/IgnoreConfiguration.cs b/src/GitVersion.Core/Configuration/IgnoreConfiguration.cs index d8c594e54d..17561aafdf 100644 --- a/src/GitVersion.Core/Configuration/IgnoreConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IgnoreConfiguration.cs @@ -5,13 +5,13 @@ namespace GitVersion.Configuration; public class IgnoreConfiguration { - public IgnoreConfiguration() => Shas = Enumerable.Empty(); + public IgnoreConfiguration() => Shas = Array.Empty(); [YamlMember(Alias = "commits-before")] public DateTimeOffset? Before { get; set; } [YamlMember(Alias = "sha")] - public IEnumerable Shas { get; set; } + public string[] Shas { get; set; } [YamlIgnore] public virtual bool IsEmpty => Before == null && Shas.Any() == false; diff --git a/src/GitVersion.Core/Configuration/Init/EditConfigStep.cs b/src/GitVersion.Core/Configuration/Init/EditConfigStep.cs index 9c3914f5a0..03200fa6ed 100644 --- a/src/GitVersion.Core/Configuration/Init/EditConfigStep.cs +++ b/src/GitVersion.Core/Configuration/Init/EditConfigStep.cs @@ -54,7 +54,7 @@ protected override string GetPrompt(GitVersionConfiguration configuration, strin 3) Set next version number 4) Branch specific configuration -5) Branch Increment mode (per commit/after tag) (Current: {configuration.VersioningMode}) +5) Branch Increment mode (per commit/after tag) (Current: {configuration.VersioningMode ?? VersionCalculation.VersioningMode.ContinuousDeployment}) 6) Assembly versioning scheme (Current: {configuration.AssemblyVersioningScheme}) 7) Setup build scripts"; diff --git a/src/GitVersion.Core/Configuration/Init/SetConfig/ConfigureBranches.cs b/src/GitVersion.Core/Configuration/Init/SetConfig/ConfigureBranches.cs index a95f8837ed..592edc3ccf 100644 --- a/src/GitVersion.Core/Configuration/Init/SetConfig/ConfigureBranches.cs +++ b/src/GitVersion.Core/Configuration/Init/SetConfig/ConfigureBranches.cs @@ -45,7 +45,7 @@ protected override string GetPrompt(GitVersionConfiguration configuration, strin private static IOrderedEnumerable> OrderedBranches(GitVersionConfiguration configuration) { - var defaultConfig = new ConfigurationBuilder().Build(); + var defaultConfig = GitFlowConfigurationBuilder.New.Build(); var defaultConfigurationBranches = defaultConfig.Branches .Where(k => !configuration.Branches.ContainsKey(k.Key)) diff --git a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs index 086aeab7cd..56598b0ecb 100644 --- a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs +++ b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs @@ -44,7 +44,7 @@ public VersionVariables CalculateVersionVariables() var gitVersionOptions = this.options.Value; - var cacheKey = this.cacheKeyFactory.Create(gitVersionOptions.ConfigInfo.OverrideConfig); + var cacheKey = this.cacheKeyFactory.Create(gitVersionOptions.ConfigInfo.OverrideConfiguration); var versionVariables = gitVersionOptions.Settings.NoCache ? default : this.gitVersionCache.LoadVersionVariablesFromDiskCache(cacheKey); if (versionVariables != null) return versionVariables; diff --git a/src/GitVersion.Core/Core/GitVersionContextFactory.cs b/src/GitVersion.Core/Core/GitVersionContextFactory.cs index 543e67d3f1..1023e3adb5 100644 --- a/src/GitVersion.Core/Core/GitVersionContextFactory.cs +++ b/src/GitVersion.Core/Core/GitVersionContextFactory.cs @@ -26,7 +26,8 @@ public GitVersionContext Create(GitVersionOptions gitVersionOptions) var currentCommit = this.repositoryStore.GetCurrentCommit(currentBranch, gitVersionOptions.RepositoryInfo.CommitId); - var configuration = this.configurationProvider.Provide(this.options.Value.ConfigInfo.OverrideConfig); + var overrideConfiguration = this.options.Value.ConfigInfo.OverrideConfiguration; + var configuration = this.configurationProvider.Provide(overrideConfiguration); if (currentBranch.IsDetachedHead) { var branchForCommit = this.repositoryStore.GetBranchesContainingCommit(currentCommit, onlyTrackedBranches: gitVersionOptions.Settings.OnlyTrackedBranches).OnlyOrDefault(); diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index d0ed30788b..a483bbc332 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -82,10 +82,9 @@ GitVersion.Common.IRepositoryStore.IsCommitOnBranch(GitVersion.ICommit? baseVers GitVersion.ConfigInfo GitVersion.ConfigInfo.ConfigFile -> string? GitVersion.ConfigInfo.ConfigInfo() -> void -GitVersion.ConfigInfo.OverrideConfig -> GitVersion.Configuration.GitVersionConfiguration? +GitVersion.ConfigInfo.OverrideConfiguration -> System.Collections.Generic.IReadOnlyDictionary? GitVersion.ConfigInfo.ShowConfig -> bool GitVersion.Configuration.BranchConfiguration -GitVersion.Configuration.BranchConfiguration.Apply(GitVersion.Configuration.BranchConfiguration! overrides) -> GitVersion.Configuration.BranchConfiguration! GitVersion.Configuration.BranchConfiguration.BranchConfiguration() -> void GitVersion.Configuration.BranchConfiguration.BranchConfiguration(GitVersion.Configuration.BranchConfiguration! branchConfiguration) -> void GitVersion.Configuration.BranchConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode? @@ -103,7 +102,6 @@ GitVersion.Configuration.BranchConfiguration.Label.get -> string? GitVersion.Configuration.BranchConfiguration.Label.set -> void GitVersion.Configuration.BranchConfiguration.LabelNumberPattern.get -> string? GitVersion.Configuration.BranchConfiguration.LabelNumberPattern.set -> void -GitVersion.Configuration.BranchConfiguration.MergeTo(GitVersion.Configuration.BranchConfiguration! targetConfig) -> void GitVersion.Configuration.BranchConfiguration.Name.get -> string! GitVersion.Configuration.BranchConfiguration.Name.set -> void GitVersion.Configuration.BranchConfiguration.PreReleaseWeight.get -> int? @@ -120,10 +118,8 @@ GitVersion.Configuration.BranchConfiguration.TracksReleaseBranches.get -> bool? GitVersion.Configuration.BranchConfiguration.TracksReleaseBranches.set -> void GitVersion.Configuration.BranchConfiguration.VersioningMode.get -> GitVersion.VersionCalculation.VersioningMode? GitVersion.Configuration.BranchConfiguration.VersioningMode.set -> void -GitVersion.Configuration.ConfigurationBuilder -GitVersion.Configuration.ConfigurationBuilder.Add(GitVersion.Configuration.GitVersionConfiguration! configuration) -> GitVersion.Configuration.ConfigurationBuilder! -GitVersion.Configuration.ConfigurationBuilder.Build() -> GitVersion.Configuration.GitVersionConfiguration! -GitVersion.Configuration.ConfigurationBuilder.ConfigurationBuilder() -> void +GitVersion.Configuration.BranchConfigurationBuilder +GitVersion.Configuration.BranchConfigurationBuilder.Build() -> GitVersion.Configuration.BranchConfiguration! GitVersion.Configuration.ConfigurationException GitVersion.Configuration.ConfigurationException.ConfigurationException(string! msg) -> void GitVersion.Configuration.ConfigurationExtensions @@ -133,6 +129,7 @@ GitVersion.Configuration.ConfigurationFileLocator.FilePath.get -> string! GitVersion.Configuration.ConfigurationFileLocator.GetConfigFilePath(string? workingDirectory) -> string? GitVersion.Configuration.ConfigurationFileLocator.HasConfigFileAt(string! workingDirectory) -> bool GitVersion.Configuration.ConfigurationFileLocator.ReadConfig(string! workingDirectory) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.ConfigurationFileLocator.ReadOverrideConfiguration(string? workingDirectory) -> System.Collections.Generic.IReadOnlyDictionary? GitVersion.Configuration.ConfigurationFileLocator.SelectConfigFilePath(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> string? GitVersion.Configuration.ConfigurationFileLocator.Verify(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> void GitVersion.Configuration.ConfigurationFileLocator.Verify(string? workingDirectory, string? projectRootDirectory) -> void @@ -142,9 +139,8 @@ GitVersion.Configuration.ConfigurationModule.RegisterTypes(Microsoft.Extensions. GitVersion.Configuration.ConfigurationProvider GitVersion.Configuration.ConfigurationProvider.ConfigurationProvider(GitVersion.IFileSystem! fileSystem, GitVersion.Logging.ILog! log, GitVersion.Configuration.IConfigurationFileLocator! configFileLocator, Microsoft.Extensions.Options.IOptions! options, GitVersion.Configuration.Init.Wizard.IConfigInitWizard! configInitWizard) -> void GitVersion.Configuration.ConfigurationProvider.Init(string! workingDirectory) -> void -GitVersion.Configuration.ConfigurationProvider.Provide(GitVersion.Configuration.GitVersionConfiguration? overrideConfiguration) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.ConfigurationProvider.Provide(System.Collections.Generic.IReadOnlyDictionary? overrideConfiguration) -> GitVersion.Configuration.GitVersionConfiguration! GitVersion.Configuration.ConfigurationSerializer -GitVersion.Configuration.ConfigurationSerializer.ConfigurationSerializer() -> void GitVersion.Configuration.EffectiveBranchConfiguration GitVersion.Configuration.EffectiveBranchConfiguration.Branch.get -> GitVersion.IBranch! GitVersion.Configuration.EffectiveBranchConfiguration.CreateNextVersion(GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.SemanticVersion! incrementedVersion) -> GitVersion.VersionCalculation.NextVersion! @@ -159,9 +155,8 @@ 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.ContinuousDeploymentFallbackLabel.get -> string? GitVersion.Configuration.EffectiveConfiguration.EffectiveConfiguration(GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.Configuration.BranchConfiguration! currentBranchConfig) -> 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, string? continuousDeploymentFallbackLabel, 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.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 GitVersion.Configuration.EffectiveConfiguration.IsReleaseBranch.get -> bool @@ -198,15 +193,9 @@ GitVersion.Configuration.GitVersionConfiguration.Branches.get -> System.Collecti GitVersion.Configuration.GitVersionConfiguration.Branches.set -> void GitVersion.Configuration.GitVersionConfiguration.CommitDateFormat.get -> string? GitVersion.Configuration.GitVersionConfiguration.CommitDateFormat.set -> void -GitVersion.Configuration.GitVersionConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode? -GitVersion.Configuration.GitVersionConfiguration.CommitMessageIncrementing.set -> void -GitVersion.Configuration.GitVersionConfiguration.ContinuousDeploymentFallbackLabel.get -> string? -GitVersion.Configuration.GitVersionConfiguration.ContinuousDeploymentFallbackLabel.set -> void GitVersion.Configuration.GitVersionConfiguration.GitVersionConfiguration() -> void GitVersion.Configuration.GitVersionConfiguration.Ignore.get -> GitVersion.Configuration.IgnoreConfiguration! GitVersion.Configuration.GitVersionConfiguration.Ignore.set -> void -GitVersion.Configuration.GitVersionConfiguration.Increment.get -> GitVersion.IncrementStrategy? -GitVersion.Configuration.GitVersionConfiguration.Increment.set -> void GitVersion.Configuration.GitVersionConfiguration.LabelPreReleaseWeight.get -> int? GitVersion.Configuration.GitVersionConfiguration.LabelPreReleaseWeight.set -> void GitVersion.Configuration.GitVersionConfiguration.LabelPrefix.get -> string? @@ -225,26 +214,25 @@ GitVersion.Configuration.GitVersionConfiguration.PatchVersionBumpMessage.get -> GitVersion.Configuration.GitVersionConfiguration.PatchVersionBumpMessage.set -> void GitVersion.Configuration.GitVersionConfiguration.SemanticVersionFormat.get -> GitVersion.SemanticVersionFormat GitVersion.Configuration.GitVersionConfiguration.SemanticVersionFormat.set -> void -GitVersion.Configuration.GitVersionConfiguration.UpdateBuildNumber.get -> bool? +GitVersion.Configuration.GitVersionConfiguration.UpdateBuildNumber.get -> bool GitVersion.Configuration.GitVersionConfiguration.UpdateBuildNumber.set -> void -GitVersion.Configuration.GitVersionConfiguration.VersioningMode.get -> GitVersion.VersionCalculation.VersioningMode? -GitVersion.Configuration.GitVersionConfiguration.VersioningMode.set -> void GitVersion.Configuration.IConfigurationFileLocator GitVersion.Configuration.IConfigurationFileLocator.FilePath.get -> string! GitVersion.Configuration.IConfigurationFileLocator.GetConfigFilePath(string! workingDirectory) -> string? GitVersion.Configuration.IConfigurationFileLocator.HasConfigFileAt(string! workingDirectory) -> bool GitVersion.Configuration.IConfigurationFileLocator.ReadConfig(string! workingDirectory) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.IConfigurationFileLocator.ReadOverrideConfiguration(string? workingDirectory) -> System.Collections.Generic.IReadOnlyDictionary? GitVersion.Configuration.IConfigurationFileLocator.SelectConfigFilePath(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> string? GitVersion.Configuration.IConfigurationFileLocator.Verify(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> void GitVersion.Configuration.IConfigurationFileLocator.Verify(string! workingDirectory, string! projectRootDirectory) -> void GitVersion.Configuration.IConfigurationProvider GitVersion.Configuration.IConfigurationProvider.Init(string! workingDirectory) -> void -GitVersion.Configuration.IConfigurationProvider.Provide(GitVersion.Configuration.GitVersionConfiguration? overrideConfiguration = null) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.IConfigurationProvider.Provide(System.Collections.Generic.IReadOnlyDictionary? overrideConfiguration = null) -> GitVersion.Configuration.GitVersionConfiguration! GitVersion.Configuration.IgnoreConfiguration GitVersion.Configuration.IgnoreConfiguration.Before.get -> System.DateTimeOffset? GitVersion.Configuration.IgnoreConfiguration.Before.set -> void GitVersion.Configuration.IgnoreConfiguration.IgnoreConfiguration() -> void -GitVersion.Configuration.IgnoreConfiguration.Shas.get -> System.Collections.Generic.IEnumerable! +GitVersion.Configuration.IgnoreConfiguration.Shas.get -> string![]! GitVersion.Configuration.IgnoreConfiguration.Shas.set -> void GitVersion.Configuration.Init.EditConfigStep GitVersion.Configuration.Init.EditConfigStep.EditConfigStep(GitVersion.Logging.IConsole! console, GitVersion.IFileSystem! fileSystem, GitVersion.Logging.ILog! log, GitVersion.Configuration.Init.Wizard.IConfigInitStepFactory! stepFactory) -> void @@ -847,14 +835,14 @@ GitVersion.VersionCalculation.Caching.GitVersionCacheKey GitVersion.VersionCalculation.Caching.GitVersionCacheKey.GitVersionCacheKey(string! value) -> void GitVersion.VersionCalculation.Caching.GitVersionCacheKey.Value.get -> string! GitVersion.VersionCalculation.Caching.GitVersionCacheKeyFactory -GitVersion.VersionCalculation.Caching.GitVersionCacheKeyFactory.Create(GitVersion.Configuration.GitVersionConfiguration? overrideConfiguration) -> GitVersion.VersionCalculation.Caching.GitVersionCacheKey! +GitVersion.VersionCalculation.Caching.GitVersionCacheKeyFactory.Create(System.Collections.Generic.IReadOnlyDictionary? overrideConfiguration) -> GitVersion.VersionCalculation.Caching.GitVersionCacheKey! GitVersion.VersionCalculation.Caching.GitVersionCacheKeyFactory.GitVersionCacheKeyFactory(GitVersion.IFileSystem! fileSystem, GitVersion.Logging.ILog! log, Microsoft.Extensions.Options.IOptions! options, GitVersion.Configuration.IConfigurationFileLocator! configFileLocator, GitVersion.IGitRepository! gitRepository, GitVersion.IGitRepositoryInfo! repositoryInfo) -> void GitVersion.VersionCalculation.Caching.IGitVersionCache GitVersion.VersionCalculation.Caching.IGitVersionCache.GetCacheDirectory() -> string! GitVersion.VersionCalculation.Caching.IGitVersionCache.LoadVersionVariablesFromDiskCache(GitVersion.VersionCalculation.Caching.GitVersionCacheKey! key) -> GitVersion.OutputVariables.VersionVariables? GitVersion.VersionCalculation.Caching.IGitVersionCache.WriteVariablesToDiskCache(GitVersion.VersionCalculation.Caching.GitVersionCacheKey! cacheKey, GitVersion.OutputVariables.VersionVariables! variablesFromCache) -> void GitVersion.VersionCalculation.Caching.IGitVersionCacheKeyFactory -GitVersion.VersionCalculation.Caching.IGitVersionCacheKeyFactory.Create(GitVersion.Configuration.GitVersionConfiguration? overrideConfiguration) -> GitVersion.VersionCalculation.Caching.GitVersionCacheKey! +GitVersion.VersionCalculation.Caching.IGitVersionCacheKeyFactory.Create(System.Collections.Generic.IReadOnlyDictionary? overrideConfiguration) -> GitVersion.VersionCalculation.Caching.GitVersionCacheKey! GitVersion.VersionCalculation.CommitMessageIncrementMode GitVersion.VersionCalculation.CommitMessageIncrementMode.Disabled = 1 -> GitVersion.VersionCalculation.CommitMessageIncrementMode GitVersion.VersionCalculation.CommitMessageIncrementMode.Enabled = 0 -> GitVersion.VersionCalculation.CommitMessageIncrementMode @@ -1116,14 +1104,16 @@ readonly GitVersion.Configuration.Init.Wizard.ConfigInitWizardStep.Log -> GitVer readonly GitVersion.Configuration.Init.Wizard.ConfigInitWizardStep.StepFactory -> GitVersion.Configuration.Init.Wizard.IConfigInitStepFactory! static GitVersion.BranchCommit.operator !=(GitVersion.BranchCommit left, GitVersion.BranchCommit right) -> bool static GitVersion.BranchCommit.operator ==(GitVersion.BranchCommit left, GitVersion.BranchCommit right) -> bool +static GitVersion.Configuration.BranchConfigurationBuilder.New.get -> GitVersion.Configuration.BranchConfigurationBuilder! static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> GitVersion.Configuration.BranchConfiguration! 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.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.GetUnknownBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.IsReleaseBranch(this GitVersion.Configuration.GitVersionConfiguration! configuration, string! branchName) -> bool +static GitVersion.Configuration.ConfigurationSerializer.Deserialize(string! input) -> T static GitVersion.Configuration.ConfigurationSerializer.Read(System.IO.TextReader! reader) -> GitVersion.Configuration.GitVersionConfiguration! +static GitVersion.Configuration.ConfigurationSerializer.Serialize(object! graph) -> string! static GitVersion.Configuration.ConfigurationSerializer.Write(GitVersion.Configuration.GitVersionConfiguration! configuration, System.IO.TextWriter! writer) -> void static GitVersion.Configuration.Init.StepResult.ExitWithoutSaving() -> GitVersion.Configuration.Init.StepResult! static GitVersion.Configuration.Init.StepResult.InvalidResponseSelected() -> GitVersion.Configuration.Init.StepResult! @@ -1240,6 +1230,24 @@ virtual GitVersion.BuildAgents.BuildAgentBase.IsDefault.get -> bool virtual GitVersion.BuildAgents.BuildAgentBase.PreventFetch() -> bool virtual GitVersion.BuildAgents.BuildAgentBase.ShouldCleanUpRemotes() -> bool virtual GitVersion.BuildAgents.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.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! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithIsSourceBranchFor(params string![]? values) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithLabel(string? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithLabelNumberPattern(string? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithName(string! value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithPreReleaseWeight(int? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithPreventIncrementOfMergedBranchVersion(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithRegex(string? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithSourceBranches(System.Collections.Generic.IEnumerable? values) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithSourceBranches(params string![]? values) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithTrackMergeTarget(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithTracksReleaseBranches(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder! +virtual GitVersion.Configuration.BranchConfigurationBuilder.WithVersioningMode(GitVersion.VersionCalculation.VersioningMode? value) -> GitVersion.Configuration.BranchConfigurationBuilder! virtual GitVersion.Configuration.IgnoreConfiguration.IsEmpty.get -> bool virtual GitVersion.Configuration.IgnoreConfiguration.ToFilters() -> System.Collections.Generic.IEnumerable! virtual GitVersion.VersionCalculation.EffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.GitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs index db79e0d847..d14b4d76b1 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs @@ -28,7 +28,7 @@ public GitVersionCacheKeyFactory(IFileSystem fileSystem, ILog log, this.repositoryInfo = repositoryInfo.NotNull(); } - public GitVersionCacheKey Create(GitVersionConfiguration? overrideConfiguration) + public GitVersionCacheKey Create(IReadOnlyDictionary? overrideConfiguration) { var gitSystemHash = GetGitSystemHash(); var configFileHash = GetConfigFileHash(); @@ -150,22 +150,16 @@ private string GetRepositorySnapshotHash() return GetHash(hash); } - private static string GetOverrideConfigHash(GitVersionConfiguration? overrideConfiguration) + private static string GetOverrideConfigHash(IReadOnlyDictionary? overrideConfiguration) { - if (overrideConfiguration == null) + if (overrideConfiguration == null || !overrideConfiguration.Any()) { return string.Empty; } // Doesn't depend on command line representation and // includes possible changes in default values of Config per se. - var stringBuilder = new StringBuilder(); - using (var stream = new StringWriter(stringBuilder)) - { - ConfigurationSerializer.Write(overrideConfiguration, stream); - stream.Flush(); - } - var configContent = stringBuilder.ToString(); + var configContent = ConfigurationSerializer.Serialize(overrideConfiguration); return GetHash(configContent); } diff --git a/src/GitVersion.Core/VersionCalculation/Caching/IGitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/IGitVersionCacheKeyFactory.cs index 9259eb3880..8a958359d6 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/IGitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/IGitVersionCacheKeyFactory.cs @@ -1,8 +1,6 @@ -using GitVersion.Configuration; - namespace GitVersion.VersionCalculation.Caching; public interface IGitVersionCacheKeyFactory { - GitVersionCacheKey Create(GitVersionConfiguration? overrideConfiguration); + GitVersionCacheKey Create(IReadOnlyDictionary? overrideConfiguration); } diff --git a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs index 77aee360d2..3340f56f49 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs @@ -48,7 +48,7 @@ public virtual NextVersion FindVersion() var preReleaseTagName = nextVersion.Configuration.GetBranchSpecificTag(this.log, Context.CurrentBranch.Name.Friendly, baseVersion.BranchNameOverride); SemanticVersion semver; - if (Context.Configuration.VersioningMode == VersioningMode.Mainline) + if (nextVersion.Configuration.VersioningMode == VersioningMode.Mainline) { semver = this.mainlineVersionCalculator.FindMainlineModeVersion(baseVersion); } @@ -212,7 +212,7 @@ private IEnumerable GetNextVersions(IBranch branch, GitVersionConfi ? baseVersion.SemanticVersion : baseVersion.SemanticVersion.IncrementVersion(incrementStrategy); - if (configuration.VersioningMode == VersioningMode.Mainline) + if (effectiveBranchConfiguration.Value.VersioningMode == VersioningMode.Mainline) { if (!(incrementedVersion.PreReleaseTag.HasTag() != true)) { diff --git a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs index 788c8c3bdc..2bd074b57e 100644 --- a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs @@ -32,7 +32,7 @@ public VersionVariables GetVariablesFor(SemanticVersion semanticVersion, Effecti { // TODO: Why do we manipulating the semantic version here in the VariableProvider? The method name is GET not MANIPULATE. // What is about the separation of concern and single-responsibility principle? - semanticVersion.PreReleaseTag.Name = configuration.ContinuousDeploymentFallbackLabel; + semanticVersion.PreReleaseTag.Name = configuration.Label; } } } diff --git a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs index 56bde020c3..5b4aff9bb4 100644 --- a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs +++ b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs @@ -81,8 +81,8 @@ public void WriteVersionInfoToBuildLog(WriteVersionInfoToBuildLog task) var versionVariables = VersionVariables.FromFile(task.VersionFile, fileSystem); var gitVersionOptions = this.options.Value; - var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfig); + var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfiguration); - gitVersionOutputTool.OutputVariables(versionVariables, configuration.UpdateBuildNumber ?? true); + gitVersionOutputTool.OutputVariables(versionVariables, configuration.UpdateBuildNumber); } } diff --git a/src/GitVersion.MsBuild/PublicAPI.Unshipped.txt b/src/GitVersion.MsBuild/PublicAPI.Unshipped.txt index 4644d7b1bf..460e4e2131 100644 --- a/src/GitVersion.MsBuild/PublicAPI.Unshipped.txt +++ b/src/GitVersion.MsBuild/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ #nullable enable +abstract GitVersion.MsBuild.GitVersionTaskBase.OnExecute() -> bool GitVersion.MsBuild.FileHelper GitVersion.MsBuild.GitVersionMsBuildModule GitVersion.MsBuild.GitVersionMsBuildModule.GitVersionMsBuildModule() -> void @@ -109,7 +110,6 @@ GitVersion.MsBuild.Tasks.UpdateAssemblyInfo.ProjectFile.set -> void GitVersion.MsBuild.Tasks.UpdateAssemblyInfo.UpdateAssemblyInfo() -> void GitVersion.MsBuild.Tasks.WriteVersionInfoToBuildLog GitVersion.MsBuild.Tasks.WriteVersionInfoToBuildLog.WriteVersionInfoToBuildLog() -> void -abstract GitVersion.MsBuild.GitVersionTaskBase.OnExecute() -> bool override GitVersion.MsBuild.Tasks.GenerateGitVersionInformation.OnExecute() -> bool override GitVersion.MsBuild.Tasks.GetVersion.OnExecute() -> bool override GitVersion.MsBuild.Tasks.UpdateAssemblyInfo.OnExecute() -> bool diff --git a/src/GitVersion.Testing/GitTestExtensions.cs b/src/GitVersion.Testing/GitTestExtensions.cs index 99d3d7a9de..e6ed671bcd 100644 --- a/src/GitVersion.Testing/GitTestExtensions.cs +++ b/src/GitVersion.Testing/GitTestExtensions.cs @@ -42,7 +42,7 @@ public static Tag MakeATaggedCommit(this IRepository repository, string tag) { var commit = repository.MakeACommit(); var existingTag = repository.Tags.SingleOrDefault(t => t.FriendlyName == tag); - return existingTag != null ? existingTag : repository.Tags.Add(tag, commit); + return existingTag ?? repository.Tags.Add(tag, commit); } public static Commit CreatePullRequestRef(this IRepository repository, string from, string to, int prNumber = 2, bool normalise = false, bool allowFastForwardMerge = false) From 062bfc4bfd70cc771aae1364fef09d403610c35d Mon Sep 17 00:00:00 2001 From: Hardy Hobeck Date: Wed, 22 Feb 2023 15:26:13 +0100 Subject: [PATCH 2/3] Update configuration.md and fix minor code review issues. --- docs/input/docs/reference/configuration.md | 8 ++++---- .../IntegrationTests/FeatureBranchScenarios.cs | 2 +- .../Configuration/ConfigurationBuilderBase.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index 463a0906c8..6946ded6b2 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -48,6 +48,10 @@ minor-version-bump-message: '\+semver:\s?(feature|minor)' patch-version-bump-message: '\+semver:\s?(fix|patch)' no-bump-message: '\+semver:\s?(none|skip)' label-pre-release-weight: 60000 +commit-date-format: yyyy-MM-dd +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict branches: develop: mode: ContinuousDeployment @@ -154,9 +158,6 @@ branches: - support ignore: sha: [] -commit-date-format: yyyy-MM-dd -merge-message-formats: {} -update-build-number: true mode: ContinuousDelivery label: '{BranchName}' increment: Inherit @@ -167,7 +168,6 @@ regex: '' tracks-release-branches: false is-release-branch: false is-mainline: false - ``` The details of the available options are as follows: diff --git a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs index ba27177d19..8b9932fb21 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -407,7 +407,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack() // merge release into main fixture.Checkout(MainBranch); fixture.MergeNoFF("release/1.0.0"); - //fixture.AssertFullSemverNew("1.0.1+2", configuration); + fixture.AssertFullSemver("1.0.1+2", configuration); // create a misnamed feature branch (i.e. it uses the default configuration) from main and verify the version fixture.BranchTo("misnamed"); diff --git a/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs index e9baff5742..494d35bfc1 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs @@ -425,8 +425,8 @@ private static void ValidateConfiguration(GitVersionConfiguration configuration) public record BranchMetaData { - public string Name { get; set; } + public string Name { get; init; } - public string RegexPattern { get; set; } + public string RegexPattern { get; init; } } } From 28d075ceceac70b1eebac5cbc7ee09b0b42f156a Mon Sep 17 00:00:00 2001 From: Hardy Hobeck Date: Wed, 22 Feb 2023 15:48:08 +0100 Subject: [PATCH 3/3] Rename Config to Configuration and ConfigInfo to ConfigurationContext --- src/GitVersion.App/Arguments.cs | 4 ++-- src/GitVersion.App/GitVersionExecutor.cs | 2 +- .../Configuration/ConfigurationFileLocatorTests.cs | 8 ++++---- src/GitVersion.Core/ConfigInfo.cs | 8 -------- .../Configuration/ConfigurationFileLocator.cs | 2 +- src/GitVersion.Core/ConfigurationContext.cs | 8 ++++++++ src/GitVersion.Core/GitVersionOptions.cs | 2 +- src/GitVersion.Core/PublicAPI.Unshipped.txt | 12 ++++++------ 8 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 src/GitVersion.Core/ConfigInfo.cs create mode 100644 src/GitVersion.Core/ConfigurationContext.cs diff --git a/src/GitVersion.App/Arguments.cs b/src/GitVersion.App/Arguments.cs index 5c082a0ce1..948a19312a 100644 --- a/src/GitVersion.App/Arguments.cs +++ b/src/GitVersion.App/Arguments.cs @@ -60,9 +60,9 @@ public GitVersionOptions ToOptions() ConfigInfo = { - ConfigFile = ConfigFile, + ConfigurationFile = ConfigFile, OverrideConfiguration = OverrideConfig, - ShowConfig = ShowConfig + ShowConfiguration = ShowConfig }, RepositoryInfo = diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index ce23c3685c..e6106e7ce7 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -152,7 +152,7 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e return true; } - if (gitVersionOptions.ConfigInfo.ShowConfig) + if (gitVersionOptions.ConfigInfo.ShowConfiguration) { var configuration = this.configurationProvider.Provide(); this.console.WriteLine(configuration.ToString()); diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs index afb7576937..191720828e 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs @@ -84,7 +84,7 @@ public class NamedConfigurationFileLocatorTests : TestBase [SetUp] public void Setup() { - this.gitVersionOptions = new GitVersionOptions { ConfigInfo = { ConfigFile = "my-config.yaml" } }; + this.gitVersionOptions = new GitVersionOptions { ConfigInfo = { ConfigurationFile = "my-config.yaml" } }; this.repoPath = DefaultRepoPath; this.workingPath = DefaultWorkingPath; @@ -140,7 +140,7 @@ public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath() { this.workingPath = DefaultRepoPath; - this.gitVersionOptions = new GitVersionOptions { ConfigInfo = { ConfigFile = "./src/my-config.yaml" } }; + this.gitVersionOptions = new GitVersionOptions { ConfigInfo = { ConfigurationFile = "./src/my-config.yaml" } }; var sp = GetServiceProvider(this.gitVersionOptions); this.configFileLocator = sp.GetRequiredService(); this.fileSystem = sp.GetRequiredService(); @@ -200,8 +200,8 @@ public void ThrowsExceptionOnCustomYmlFileDoesNotExist() var exception = Should.Throw(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); - var workingPathFileConfig = PathHelper.Combine(this.workingPath, this.gitVersionOptions.ConfigInfo.ConfigFile); - var repoPathFileConfig = PathHelper.Combine(this.repoPath, this.gitVersionOptions.ConfigInfo.ConfigFile); + var workingPathFileConfig = PathHelper.Combine(this.workingPath, this.gitVersionOptions.ConfigInfo.ConfigurationFile); + var repoPathFileConfig = PathHelper.Combine(this.repoPath, this.gitVersionOptions.ConfigInfo.ConfigurationFile); var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'"; exception.Message.ShouldBe(expectedMessage); } diff --git a/src/GitVersion.Core/ConfigInfo.cs b/src/GitVersion.Core/ConfigInfo.cs deleted file mode 100644 index 907a04bfdf..0000000000 --- a/src/GitVersion.Core/ConfigInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace GitVersion; - -public class ConfigInfo -{ - public string? ConfigFile; - public IReadOnlyDictionary? OverrideConfiguration; - public bool ShowConfig; -} diff --git a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs index 31ce9adc5e..07bbce9500 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs @@ -12,7 +12,7 @@ public class ConfigurationFileLocator : IConfigurationFileLocator public ConfigurationFileLocator(IFileSystem fileSystem, IOptions options) { this.fileSystem = fileSystem; - var configFile = options.Value.ConfigInfo.ConfigFile; + var configFile = options.Value.ConfigInfo.ConfigurationFile; FilePath = !configFile.IsNullOrWhiteSpace() ? configFile : DefaultFileName; } diff --git a/src/GitVersion.Core/ConfigurationContext.cs b/src/GitVersion.Core/ConfigurationContext.cs new file mode 100644 index 0000000000..021927e259 --- /dev/null +++ b/src/GitVersion.Core/ConfigurationContext.cs @@ -0,0 +1,8 @@ +namespace GitVersion; + +public class ConfigurationContext +{ + public string? ConfigurationFile; + public IReadOnlyDictionary? OverrideConfiguration; + public bool ShowConfiguration; +} diff --git a/src/GitVersion.Core/GitVersionOptions.cs b/src/GitVersion.Core/GitVersionOptions.cs index d282e8b30a..f50836d252 100644 --- a/src/GitVersion.Core/GitVersionOptions.cs +++ b/src/GitVersion.Core/GitVersionOptions.cs @@ -8,7 +8,7 @@ public class GitVersionOptions public AssemblyInfoData AssemblyInfo { get; } = new(); public AuthenticationInfo Authentication { get; } = new(); - public ConfigInfo ConfigInfo { get; } = new(); + public ConfigurationContext ConfigInfo { get; } = new(); public RepositoryInfo RepositoryInfo { get; } = new(); public WixInfo WixInfo { get; } = new(); public Settings Settings { get; } = new(); diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index a483bbc332..91344d9b29 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -79,11 +79,6 @@ GitVersion.Common.IRepositoryStore.GetTargetBranch(string? targetBranchName) -> GitVersion.Common.IRepositoryStore.GetValidVersionTags(string? tagPrefixRegex, GitVersion.SemanticVersionFormat versionFormat, System.DateTimeOffset? olderThan = null) -> System.Collections.Generic.IEnumerable<(GitVersion.ITag! Tag, GitVersion.SemanticVersion! Semver, GitVersion.ICommit! Commit)>! GitVersion.Common.IRepositoryStore.GetVersionTagsOnBranch(GitVersion.IBranch! branch, string? tagPrefixRegex, GitVersion.SemanticVersionFormat versionFormat) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.IsCommitOnBranch(GitVersion.ICommit? baseVersionSource, GitVersion.IBranch! branch, GitVersion.ICommit! firstMatchingCommit) -> bool -GitVersion.ConfigInfo -GitVersion.ConfigInfo.ConfigFile -> string? -GitVersion.ConfigInfo.ConfigInfo() -> void -GitVersion.ConfigInfo.OverrideConfiguration -> System.Collections.Generic.IReadOnlyDictionary? -GitVersion.ConfigInfo.ShowConfig -> bool GitVersion.Configuration.BranchConfiguration GitVersion.Configuration.BranchConfiguration.BranchConfiguration() -> void GitVersion.Configuration.BranchConfiguration.BranchConfiguration(GitVersion.Configuration.BranchConfiguration! branchConfiguration) -> void @@ -288,6 +283,11 @@ GitVersion.Configuration.Init.Wizard.PickBranchingStrategy3Step GitVersion.Configuration.Init.Wizard.PickBranchingStrategy3Step.PickBranchingStrategy3Step(GitVersion.Logging.IConsole! console, GitVersion.IFileSystem! fileSystem, GitVersion.Logging.ILog! log, GitVersion.Configuration.Init.Wizard.IConfigInitStepFactory! stepFactory) -> void GitVersion.Configuration.Init.Wizard.PickBranchingStrategyStep GitVersion.Configuration.Init.Wizard.PickBranchingStrategyStep.PickBranchingStrategyStep(GitVersion.Logging.IConsole! console, GitVersion.IFileSystem! fileSystem, GitVersion.Logging.ILog! log, GitVersion.Configuration.Init.Wizard.IConfigInitStepFactory! stepFactory) -> void +GitVersion.ConfigurationContext +GitVersion.ConfigurationContext.ConfigurationContext() -> void +GitVersion.ConfigurationContext.ConfigurationFile -> string? +GitVersion.ConfigurationContext.OverrideConfiguration -> System.Collections.Generic.IReadOnlyDictionary? +GitVersion.ConfigurationContext.ShowConfiguration -> bool GitVersion.Environment GitVersion.Environment.Environment() -> void GitVersion.Environment.GetEnvironmentVariable(string! variableName) -> string? @@ -370,7 +370,7 @@ GitVersion.GitVersionModule.GitVersionModule() -> void GitVersion.GitVersionOptions GitVersion.GitVersionOptions.AssemblyInfo.get -> GitVersion.AssemblyInfoData! GitVersion.GitVersionOptions.Authentication.get -> GitVersion.AuthenticationInfo! -GitVersion.GitVersionOptions.ConfigInfo.get -> GitVersion.ConfigInfo! +GitVersion.GitVersionOptions.ConfigInfo.get -> GitVersion.ConfigurationContext! GitVersion.GitVersionOptions.Diag -> bool GitVersion.GitVersionOptions.GitVersionOptions() -> void GitVersion.GitVersionOptions.Init -> bool