From e0b6deb66169fbbc00381d5fa8e4e9c30e538f86 Mon Sep 17 00:00:00 2001 From: senritsu Date: Mon, 13 Sep 2021 19:00:45 +0200 Subject: [PATCH 1/3] add unit test for issues with hotfix branches details can be found in in #2454 --- .../IntegrationTests/HotfixBranchScenarios.cs | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index eab63072d9..4637553c2d 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -19,7 +19,7 @@ public void PatchLatestReleaseExample() using var fixture = new BaseGitFlowRepositoryFixture("1.2.0"); // create hotfix Commands.Checkout(fixture.Repository, MainBranch); - Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfix-1.2.1")); + Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfix/1.2.1")); fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.1+1"); @@ -33,7 +33,7 @@ public void PatchLatestReleaseExample() // Merge hotfix branch to main Commands.Checkout(fixture.Repository, MainBranch); - fixture.Repository.MergeNoFF("hotfix-1.2.1", Generate.SignatureNow()); + fixture.Repository.MergeNoFF("hotfix/1.2.1", Generate.SignatureNow()); fixture.AssertFullSemver("1.2.1+4"); fixture.Repository.ApplyTag("1.2.1"); @@ -43,7 +43,7 @@ public void PatchLatestReleaseExample() Commands.Checkout(fixture.Repository, "develop"); fixture.AssertFullSemver("1.3.0-alpha.1"); - fixture.Repository.MergeNoFF("hotfix-1.2.1", Generate.SignatureNow()); + fixture.Repository.MergeNoFF("hotfix/1.2.1", Generate.SignatureNow()); fixture.AssertFullSemver("1.3.0-alpha.5"); } @@ -227,5 +227,55 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() fixture.AssertFullSemver("4.5.1-beta.2", config); } + [Test] + public void HotfixMergeIncrementsVersion() + { + using var fixture = new EmptyRepositoryFixture(); + + // initialize gitflow + + const string devBranch = "develop"; + + fixture.Repository.MakeACommit("setup repo"); + fixture.Repository.CreateBranch(devBranch); + Commands.Checkout(fixture.Repository, devBranch); + + // make some changes on dev + + fixture.Repository.MakeACommit("add stuff"); + fixture.Repository.MakeACommit("add more stuff"); + + // start a release + + const string releaseBranch = "release/1.0"; + + fixture.Repository.CreateBranch(releaseBranch); + Commands.Checkout(fixture.Repository, releaseBranch); + fixture.Repository.MakeACommit("fix some minor thing"); + + fixture.AssertFullSemver("1.0.0-beta.1+1"); + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(releaseBranch, Generate.SignatureNow()); + + fixture.AssertFullSemver("1.0.0+0"); + fixture.ApplyTag("1.0"); + fixture.AssertFullSemver("1.0.0"); + + // start hotfix + + const string hotfixBranch = "hotfix/something-important"; + + fixture.Repository.CreateBranch(hotfixBranch); + fixture.Repository.MakeACommit("fix the important issue"); + // fixture.AssertFullSemver("1.0.1-beta.1+1"); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.1+1"); // PASSES + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(hotfixBranch, Generate.SignatureNow()); + + // NOTE unsure if build metadata should be +1 in this case + fixture.AssertFullSemver("1.0.1+1"); + } } } From 48b0e9dadd97344aac3142dc5cdcb0f1f3a2a48c Mon Sep 17 00:00:00 2001 From: senritsu Date: Mon, 13 Sep 2021 19:26:59 +0200 Subject: [PATCH 2/3] use same config as other tests --- .../IntegrationTests/HotfixBranchScenarios.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index 4637553c2d..0ea385fb90 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -230,6 +230,12 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() [Test] public void HotfixMergeIncrementsVersion() { + var config = new Config + { + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, + VersioningMode = VersioningMode.ContinuousDeployment + }; + using var fixture = new EmptyRepositoryFixture(); // initialize gitflow @@ -253,14 +259,14 @@ public void HotfixMergeIncrementsVersion() Commands.Checkout(fixture.Repository, releaseBranch); fixture.Repository.MakeACommit("fix some minor thing"); - fixture.AssertFullSemver("1.0.0-beta.1+1"); + fixture.AssertFullSemver("1.0.0-beta.1", config); Commands.Checkout(fixture.Repository, MainBranch); fixture.Repository.MergeNoFF(releaseBranch, Generate.SignatureNow()); - fixture.AssertFullSemver("1.0.0+0"); + fixture.AssertFullSemver("1.0.0-ci.0", config); fixture.ApplyTag("1.0"); - fixture.AssertFullSemver("1.0.0"); + fixture.AssertFullSemver("1.0.0", config); // start hotfix @@ -268,14 +274,16 @@ public void HotfixMergeIncrementsVersion() fixture.Repository.CreateBranch(hotfixBranch); fixture.Repository.MakeACommit("fix the important issue"); - // fixture.AssertFullSemver("1.0.1-beta.1+1"); // FAILS, not sure if hotfixes should have beta tag - fixture.AssertFullSemver("1.0.1+1"); // PASSES + // fixture.AssertFullSemver("1.0.1-beta.1"); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.1-ci.1", config); // PASSES + fixture.Repository.MakeACommit("fix something else"); + // fixture.AssertFullSemver("1.0.1-beta.2"); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.1-ci.2", config); // PASSES Commands.Checkout(fixture.Repository, MainBranch); fixture.Repository.MergeNoFF(hotfixBranch, Generate.SignatureNow()); - // NOTE unsure if build metadata should be +1 in this case - fixture.AssertFullSemver("1.0.1+1"); + fixture.AssertFullSemver("1.0.1-ci.2", config); } } } From 65ac50eb636d1c2e830043a3789e3cb45ee159ea Mon Sep 17 00:00:00 2001 From: senritsu Date: Mon, 4 Oct 2021 15:44:41 +0200 Subject: [PATCH 3/3] expand test scenario to use multiple hotfixes and different configs --- .../IntegrationTests/HotfixBranchScenarios.cs | 87 ++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index 0ea385fb90..7582100d11 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -228,7 +228,7 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() } [Test] - public void HotfixMergeIncrementsVersion() + public void HotfixMergeIncrementsVersionWithModeContinuousDeployment() { var config = new Config { @@ -268,7 +268,7 @@ public void HotfixMergeIncrementsVersion() fixture.ApplyTag("1.0"); fixture.AssertFullSemver("1.0.0", config); - // start hotfix + // start first hotfix const string hotfixBranch = "hotfix/something-important"; @@ -284,6 +284,89 @@ public void HotfixMergeIncrementsVersion() fixture.Repository.MergeNoFF(hotfixBranch, Generate.SignatureNow()); fixture.AssertFullSemver("1.0.1-ci.2", config); + + // start second hotfix + + const string hotfix2Branch = "hotfix/another-important-thing"; + + fixture.Repository.CreateBranch(hotfix2Branch); + fixture.Repository.MakeACommit("fix the new issue"); + // fixture.AssertFullSemver("1.0.2-beta.1"); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.2-ci.1", config); // FAILS, version is 1.0.1-ci.3 + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(hotfix2Branch, Generate.SignatureNow()); + + fixture.AssertFullSemver("1.0.2-ci.1", config); // FAILS, version is 1.0.1-ci.3 + } + + [Test] + public void HotfixMergeIncrementsVersionWithDefaultConfig() + { + var config = new Config(); + + using var fixture = new EmptyRepositoryFixture(); + + // initialize gitflow + + const string devBranch = "develop"; + + fixture.Repository.MakeACommit("setup repo"); + fixture.Repository.CreateBranch(devBranch); + Commands.Checkout(fixture.Repository, devBranch); + + // make some changes on dev + + fixture.Repository.MakeACommit("add stuff"); + fixture.Repository.MakeACommit("add more stuff"); + + // start a release + + const string releaseBranch = "release/1.0"; + + fixture.Repository.CreateBranch(releaseBranch); + Commands.Checkout(fixture.Repository, releaseBranch); + fixture.Repository.MakeACommit("fix some minor thing"); + + fixture.AssertFullSemver("1.0.0-beta.1+1", config); + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(releaseBranch, Generate.SignatureNow()); + + fixture.AssertFullSemver("1.0.0+0", config); + fixture.ApplyTag("1.0"); + fixture.AssertFullSemver("1.0.0", config); + + // start first hotfix + + const string hotfixBranch = "hotfix/something-important"; + + fixture.Repository.CreateBranch(hotfixBranch); + fixture.Repository.MakeACommit("fix the important issue"); + // fixture.AssertFullSemver("1.0.1-beta.1+1", config); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.1+1", config); + fixture.Repository.MakeACommit("fix something else"); + // fixture.AssertFullSemver("1.0.1-beta.2+2", config); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.1+2", config); + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(hotfixBranch, Generate.SignatureNow()); + + fixture.AssertFullSemver("1.0.1+2", config); + + // start second hotfix + + const string hotfix2Branch = "hotfix/another-important-thing"; + + fixture.Repository.CreateBranch(hotfix2Branch); + fixture.Repository.MakeACommit("fix the new issue"); + // fixture.AssertFullSemver("1.0.2-beta.1+1", config); // FAILS, not sure if hotfixes should have beta tag + fixture.AssertFullSemver("1.0.2+1", config); // FAILS, version is 1.0.1+3 + + Commands.Checkout(fixture.Repository, MainBranch); + fixture.Repository.MergeNoFF(hotfix2Branch, Generate.SignatureNow()); + + fixture.AssertFullSemver("1.0.2+1", config); // FAILS, version is 1.0.1+3 } } }