From edc900e690cb33d9066904009d4a823b77a10936 Mon Sep 17 00:00:00 2001 From: Dawid Kaliszewski Date: Fri, 11 Aug 2023 16:14:41 +0200 Subject: [PATCH] Test implemented --- .../MainlineDevelopmentMode.cs | 93 +++++++++++++++++++ src/GitVersion.Testing/GitTestExtensions.cs | 3 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs index 7910912faf..87e1c0ebe3 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs @@ -585,4 +585,97 @@ public void NoBumpMessageTakesPrecedenceOverBumpMessage(string commitMessage) fixture.AssertFullSemver("1.0.0", conventionalCommitsConfig); } + + [Test] + public void VerifyIssue3644BumpsMajorBasedOnLastTagNotTheFullHistory() + { + /* +mode: Mainline +assembly-versioning-format: '{Major}.{Minor}.{Patch}' +assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber ?? 0}' +branches: + master: + is-mainline: true + increment: None + major: + regex: ^major[\/-] + increment: Major + source-branches: ['master'] + minor: + regex: ^minor[\/-] + increment: Minor + source-branches: ['master', 'support'] + patch: + regex: ^patch[\/-] + increment: Patch + source-branches: ['master', 'support'] + support: + is-mainline: true + regex: ^support[/-] + tag: '' + increment: None + source-branches: ['master'] +*/ + + var configuration = GitFlowConfigurationBuilder.New + .WithBranch(MainBranch, builder => builder + .WithVersioningMode(VersioningMode.Mainline) + .WithIncrement(IncrementStrategy.None) + .WithIsMainline(true)) + .WithBranch("major", builder => builder + .WithRegularExpression("^major[\\/-]") + .WithIncrement(IncrementStrategy.Major) + .WithSourceBranches(MainBranch)) + .WithBranch("minor", builder => builder + .WithRegularExpression("^minor[\\/-]") + .WithIncrement(IncrementStrategy.Minor) + .WithSourceBranches(MainBranch)) + .WithBranch("patch", builder => builder + .WithRegularExpression("^patch[\\/-]") + .WithIncrement(IncrementStrategy.Patch) + .WithSourceBranches(MainBranch)) + .WithBranch("support", builder => builder + .WithVersioningMode(VersioningMode.Mainline) + .WithIncrement(IncrementStrategy.None) + .WithRegularExpression("^support[\\/-]") + .WithIsMainline(true) + .WithSourceBranches(MainBranch)) + .Build(); + + // implement history from the issue + using var fixture = new EmptyRepositoryFixture(); + fixture.MakeACommit("First"); + fixture.MakeACommit("New file added"); + fixture.ApplyTag("v1.0.0"); + fixture.MakeACommit("Merged PR 123: new feature"); + fixture.ApplyTag("v2.0.2"); + + // three branches, three merges to main + fixture.BranchTo("minor/new-feature-1"); + fixture.MakeACommit("New class added"); + fixture.Checkout(MainBranch); + fixture.MergeNoFF("minor/new-feature-1"); + + fixture.BranchTo("minor/new-feature-2"); + fixture.MakeACommit("New class added"); + fixture.Checkout(MainBranch); + fixture.MergeNoFF("minor/new-feature-2"); + + fixture.BranchTo("minor/new-feature-3"); + fixture.MakeACommit("New class added"); + fixture.Checkout(MainBranch); + fixture.MergeNoFF("minor/new-feature-3"); + + fixture.ApplyTag("v2.1.0"); + + // minor branch squashed + fixture.MakeACommit("Merged PR 127: squashed feature"); + fixture.ApplyTag("v2.6.0"); + + // let's implement a breaking change + fixture.BranchTo("major/breaking-change"); + fixture.MakeACommit("Breaking change implemented"); + + fixture.AssertFullSemver("3.0.0-breaking-change.1", configuration); + } } diff --git a/src/GitVersion.Testing/GitTestExtensions.cs b/src/GitVersion.Testing/GitTestExtensions.cs index e4a5661608..a8969b76db 100644 --- a/src/GitVersion.Testing/GitTestExtensions.cs +++ b/src/GitVersion.Testing/GitTestExtensions.cs @@ -11,7 +11,8 @@ public static class GitTestExtensions public static void MergeNoFF(this IRepository repository, string branch) => MergeNoFF(repository, branch, Generate.SignatureNow()); - public static void MergeNoFF(this IRepository repository, string branch, Signature sig) => repository.Merge(repository.Branches[branch], sig, new MergeOptions + public static void MergeNoFF(this IRepository repository, string branch, Signature sig) => + repository.Merge(repository.Branches[branch], sig, new MergeOptions { FastForwardStrategy = FastForwardStrategy.NoFastForward });