From c8f28d1cadc3024ac5d690dcffe345c5f9c176c1 Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Fri, 9 Sep 2022 20:05:48 +0200 Subject: [PATCH 1/8] repro steps for issue #3020 --- .../Issue3020FailedToInherit.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs diff --git a/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs b/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs new file mode 100644 index 0000000000..124b24b333 --- /dev/null +++ b/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs @@ -0,0 +1,77 @@ +using GitTools.Testing; +using GitVersion.Core.Tests.Helpers; +using GitVersion.Extensions; +using GitVersion.Model.Configuration; +using GitVersion.VersionCalculation; +using LibGit2Sharp; +using NUnit.Framework; +using Shouldly; + +namespace GitVersion.Core.Tests.IntegrationTests; + +public class Issue3020FailedToInherit : TestBase +{ + private readonly Config config = new() + { + VersioningMode = VersioningMode.ContinuousDeployment, + Branches = new Dictionary + { + { MainBranch, new BranchConfig { Tag = "beta", Increment = IncrementStrategy.Minor } }, + { "pull-request", new BranchConfig { Tag = "alpha-pr" } }, + { "support", new BranchConfig { Tag = "beta" } } + } + }; + + [Test] + public void LocalOnly() + { + var fixture = PrepareLocalRepo(); + + fixture.AssertFullSemver("1.0.2-alpha-pr0002.2", config); + + fixture.Repository.DumpGraph(); + } + + [Test] + public void WithRemote() + { + var fixture = PrepareLocalRepo(); + + var local = fixture.CloneRepository(); + local.Checkout("origin/hotfix/v1.0.2"); + local.BranchTo("hotfix/v1.0.2", "hotfix"); + local.Checkout("origin/support/v1.0.x"); + local.BranchTo("support/v1.0.x", "support"); + local.Checkout("origin/main"); + local.BranchTo("main", "main"); + local.Checkout("pull/2/merge"); + + local.AssertFullSemver("1.0.2-alpha-pr0002.2", config); + + local.Repository.DumpGraph(); + } + + private static RepositoryFixtureBase PrepareLocalRepo() + { + var fixture = new EmptyRepositoryFixture(); + + fixture.Repository.MakeACommit("First commit"); + fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); + + fixture.Repository.MakeACommit("Merged PR 1: new feature"); + + fixture.Checkout("tags/v1.0.0"); + fixture.BranchTo("support/v1.0.x", "support"); + fixture.Repository.MakeACommit("hotfix 1"); + fixture.Repository.ApplyTag("v1.0.1", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "hotfix 1"); + + fixture.BranchTo("hotfix/v1.0.2", "hotfix"); + fixture.Repository.MakeACommit("hotfix 2"); + + fixture.Checkout("support/v1.0.x"); + fixture.BranchTo("pull/2/merge", "pr-merge"); + fixture.MergeNoFF("hotfix/v1.0.2"); + + return fixture; + } +} From 1e44f8519fd17ade7cabc52c305ea1ec895f8cc0 Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Mon, 12 Sep 2022 19:33:39 +0200 Subject: [PATCH 2/8] add also test closing feature PR --- .../Issue3020FailedToInherit.cs | 68 +++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs b/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs index 124b24b333..4f07829547 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs @@ -1,11 +1,9 @@ using GitTools.Testing; using GitVersion.Core.Tests.Helpers; -using GitVersion.Extensions; using GitVersion.Model.Configuration; using GitVersion.VersionCalculation; using LibGit2Sharp; using NUnit.Framework; -using Shouldly; namespace GitVersion.Core.Tests.IntegrationTests; @@ -17,15 +15,15 @@ public class Issue3020FailedToInherit : TestBase Branches = new Dictionary { { MainBranch, new BranchConfig { Tag = "beta", Increment = IncrementStrategy.Minor } }, - { "pull-request", new BranchConfig { Tag = "alpha-pr" } }, + { "pull-request", new BranchConfig { Tag = "alpha-pr", Increment = IncrementStrategy.Inherit } }, // Inherit is indeed the default { "support", new BranchConfig { Tag = "beta" } } } }; [Test] - public void LocalOnly() + public void MergingHotFixIntoSupportLocalOnly() { - var fixture = PrepareLocalRepo(); + using var fixture = PrepareLocalRepoForHotFix(); fixture.AssertFullSemver("1.0.2-alpha-pr0002.2", config); @@ -33,25 +31,25 @@ public void LocalOnly() } [Test] - public void WithRemote() + public void MergingHotFixIntoSupportWithRemote() { - var fixture = PrepareLocalRepo(); + using var fixture = PrepareLocalRepoForHotFix(); - var local = fixture.CloneRepository(); + using var local = fixture.CloneRepository(); local.Checkout("origin/hotfix/v1.0.2"); local.BranchTo("hotfix/v1.0.2", "hotfix"); local.Checkout("origin/support/v1.0.x"); local.BranchTo("support/v1.0.x", "support"); - local.Checkout("origin/main"); - local.BranchTo("main", "main"); + local.Checkout($"origin/{MainBranch}"); + local.BranchTo(MainBranch, MainBranch); local.Checkout("pull/2/merge"); - + local.AssertFullSemver("1.0.2-alpha-pr0002.2", config); local.Repository.DumpGraph(); } - private static RepositoryFixtureBase PrepareLocalRepo() + private static RepositoryFixtureBase PrepareLocalRepoForHotFix() { var fixture = new EmptyRepositoryFixture(); @@ -74,4 +72,50 @@ private static RepositoryFixtureBase PrepareLocalRepo() return fixture; } + + [Test] + public void MergingFeatureIntoMainLocalOnly() + { + using var fixture = PrepareLocalRepoForFeature(); + + fixture.AssertFullSemver("1.1.0-alpha-pr0002.3", config); + + fixture.Repository.DumpGraph(); + } + + [Test] + public void MergingFeatureIntoMainWithRemote() + { + using var fixture = PrepareLocalRepoForFeature(); + + using var local = fixture.CloneRepository(); + local.Checkout("origin/feature/my-incredible-feature"); + local.BranchTo("feature/my-incredible-feature", "feature"); + local.Checkout($"origin/{MainBranch}"); + local.BranchTo(MainBranch, MainBranch); + local.Checkout("pull/2/merge"); + + local.AssertFullSemver("1.1.0-alpha-pr0002.3", config); + + local.Repository.DumpGraph(); + } + + private static RepositoryFixtureBase PrepareLocalRepoForFeature() + { + var fixture = new EmptyRepositoryFixture(); + + fixture.Repository.MakeACommit("First commit"); + fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); + + fixture.Repository.MakeACommit("Merged PR 1: new feature"); + + fixture.BranchTo("feature/my-incredible-feature", "feature"); + fixture.Repository.MakeACommit("incredible feature"); + + fixture.Checkout(MainBranch); + fixture.BranchTo("pull/2/merge", "pr-merge"); + fixture.MergeNoFF("feature/my-incredible-feature"); + + return fixture; + } } From 968985e88b8831e972ebd5d582e7797bff11ff92 Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 13 Sep 2022 11:54:37 +0200 Subject: [PATCH 3/8] excludes remote while ExcludingBranches --- .../Configuration/BranchConfigurationCalculator.cs | 2 +- .../Core/Abstractions/IRepositoryStore.cs | 2 +- src/GitVersion.Core/Core/RepositoryStore.cs | 10 +++++++++- src/GitVersion.Core/PublicAPI.Unshipped.txt | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs b/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs index fec7c7906c..a628435cab 100644 --- a/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs +++ b/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs @@ -89,7 +89,7 @@ private BranchConfig InheritBranchConfiguration(int recursions, IBranch targetBr { excludedInheritBranches.Add(excludedBranch); } - var branchesToEvaluate = this.repositoryStore.ExcludingBranches(excludedInheritBranches) + var branchesToEvaluate = this.repositoryStore.ExcludingBranches(excludedInheritBranches, excludeRemotes: true) .Distinct(new LocalRemoteBranchEqualityComparer()) .ToList(); diff --git a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs index 113472f668..67c25ba82c 100644 --- a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs +++ b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs @@ -23,7 +23,7 @@ public interface IRepositoryStore IEnumerable GetBranchesForCommit(ICommit commit); IEnumerable GetExcludedInheritBranches(Config configuration); IEnumerable GetReleaseBranches(IEnumerable> releaseBranchConfig); - IEnumerable ExcludingBranches(IEnumerable branchesToExclude); + IEnumerable ExcludingBranches(IEnumerable branchesToExclude, bool excludeRemotes = false); IEnumerable GetBranchesContainingCommit(ICommit? commit, IEnumerable? branches = null, bool onlyTrackedBranches = false); IDictionary> GetMainlineBranches(ICommit commit, Config configuration, IEnumerable>? mainlineBranchConfigs); diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index e13385e2bf..a3dfa44f49 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -166,7 +166,15 @@ public IEnumerable GetExcludedInheritBranches(Config configuration) public IEnumerable GetReleaseBranches(IEnumerable> releaseBranchConfig) => this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig)); - public IEnumerable ExcludingBranches(IEnumerable branchesToExclude) => this.repository.Branches.ExcludeBranches(branchesToExclude); + public IEnumerable ExcludingBranches(IEnumerable branchesToExclude, bool excludeRemotes = false) + { + var branches = this.repository.Branches.ExcludeBranches(branchesToExclude); + if (excludeRemotes) + { + branches = branches.Where(b => !b.IsRemote); + } + return branches; + } public IEnumerable GetBranchesContainingCommit(ICommit? commit, IEnumerable? branches = null, bool onlyTrackedBranches = false) { diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index e69de29bb2..19111773ed 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable! \ No newline at end of file From 29b7b31534ace9681c0ff27b8668aa97d4e85429 Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 13 Sep 2022 13:46:27 +0200 Subject: [PATCH 4/8] improve legibility and consistency --- .../Configuration/BranchConfigurationCalculator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs b/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs index a628435cab..3386c2eb8f 100644 --- a/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs +++ b/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs @@ -89,7 +89,8 @@ private BranchConfig InheritBranchConfiguration(int recursions, IBranch targetBr { excludedInheritBranches.Add(excludedBranch); } - var branchesToEvaluate = this.repositoryStore.ExcludingBranches(excludedInheritBranches, excludeRemotes: true) + var branchesToEvaluate = this.repositoryStore + .ExcludingBranches(excludedInheritBranches, excludeRemotes: true) .Distinct(new LocalRemoteBranchEqualityComparer()) .ToList(); From 4f8cfe45af65ef2dbc9daebaf8ce2de6e4945f4d Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 13 Sep 2022 13:57:47 +0200 Subject: [PATCH 5/8] moved changes of public api to shipped file --- src/GitVersion.Core/PublicAPI.Shipped.txt | 4 ++-- src/GitVersion.Core/PublicAPI.Unshipped.txt | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index 58818b425b..b7671bf2fd 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -145,7 +145,7 @@ GitVersion.CommitSortStrategies.Time = 2 -> GitVersion.CommitSortStrategies GitVersion.CommitSortStrategies.Topological = 1 -> GitVersion.CommitSortStrategies GitVersion.Common.IRepositoryStore GitVersion.Common.IRepositoryStore.DetermineIncrementedField(GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.GitVersionContext! context) -> GitVersion.VersionField? -GitVersion.Common.IRepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude) -> System.Collections.Generic.IEnumerable! +GitVersion.Common.IRepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.FindBranch(string? branchName) -> GitVersion.IBranch? GitVersion.Common.IRepositoryStore.FindCommitBranchWasBranchedFrom(GitVersion.IBranch? branch, GitVersion.Model.Configuration.Config! configuration, params GitVersion.IBranch![]! excludedBranches) -> GitVersion.BranchCommit GitVersion.Common.IRepositoryStore.FindMainBranch(GitVersion.Model.Configuration.Config! configuration) -> GitVersion.IBranch? @@ -844,7 +844,7 @@ GitVersion.RepositoryInfo.TargetBranch -> string? GitVersion.RepositoryInfo.TargetUrl -> string? GitVersion.RepositoryStore GitVersion.RepositoryStore.DetermineIncrementedField(GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.GitVersionContext! context) -> GitVersion.VersionField? -GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude) -> System.Collections.Generic.IEnumerable! +GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable! GitVersion.RepositoryStore.FindBranch(string? branchName) -> GitVersion.IBranch? GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(GitVersion.IBranch? branch, GitVersion.Model.Configuration.Config! configuration, params GitVersion.IBranch![]! excludedBranches) -> GitVersion.BranchCommit GitVersion.RepositoryStore.FindMainBranch(GitVersion.Model.Configuration.Config! configuration) -> GitVersion.IBranch? diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 19111773ed..e69de29bb2 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -1 +0,0 @@ -GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable! \ No newline at end of file From 73daf94b12e29dd29bb61c9e4f57423427371ea9 Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 13 Sep 2022 14:29:04 +0200 Subject: [PATCH 6/8] move integration test inside HotfixBranchScenarios --- .../IntegrationTests/HotfixBranchScenarios.cs | 117 +++++++++++++++++ .../Issue3020FailedToInherit.cs | 121 ------------------ 2 files changed, 117 insertions(+), 121 deletions(-) delete mode 100644 src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index 614260e171..4abd66fbbf 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -226,4 +226,121 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() fixture.AssertFullSemver("4.5.1-beta.2", config); } + [Test] + public void MergingHotFixIntoSupportLocalOnly() + { + var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); + + using var fixture = GivenIHaveALocalRepositoryWithAnHotFixMergedInAPullRequestBranch(); + + fixture.AssertFullSemver("1.0.2-alpha-pr0002.2", config); + + fixture.Repository.DumpGraph(); + } + + [Test] + public void MergingHotFixIntoSupportWithRemote() + { + var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); + + using var fixture = GivenIHaveALocalRepositoryWithAnHotFixMergedInAPullRequestBranch(); + + using var local = fixture.CloneRepository(); + local.Checkout("origin/hotfix/v1.0.2"); + local.BranchTo("hotfix/v1.0.2", "hotfix"); + local.Checkout("origin/support/v1.0.x"); + local.BranchTo("support/v1.0.x", "support"); + local.Checkout($"origin/{MainBranch}"); + local.BranchTo(MainBranch, MainBranch); + local.Checkout("pull/2/merge"); + + local.AssertFullSemver("1.0.2-alpha-pr0002.2", config); + + local.Repository.DumpGraph(); + } + + [Test] + public void MergingFeatureIntoMainLocalOnly() + { + var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); + + using var fixture = GivenIHaveALocalRepositoryWithAFeatureMergedInAPullRequestBranch(); + + fixture.AssertFullSemver("1.1.0-alpha-pr0002.3", config); + + fixture.Repository.DumpGraph(); + } + + [Test] + public void MergingFeatureIntoMainWithRemote() + { + var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); + + using var fixture = GivenIHaveALocalRepositoryWithAFeatureMergedInAPullRequestBranch(); + + using var local = fixture.CloneRepository(); + local.Checkout("origin/feature/my-incredible-feature"); + local.BranchTo("feature/my-incredible-feature", "feature"); + local.Checkout($"origin/{MainBranch}"); + local.BranchTo(MainBranch, MainBranch); + local.Checkout("pull/2/merge"); + + local.AssertFullSemver("1.1.0-alpha-pr0002.3", config); + + local.Repository.DumpGraph(); + } + + private static RepositoryFixtureBase GivenIHaveALocalRepositoryWithAnHotFixMergedInAPullRequestBranch() + { + var fixture = new EmptyRepositoryFixture(); + + fixture.Repository.MakeACommit("First commit"); + fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); + + fixture.Repository.MakeACommit("Merged PR 1: new feature"); + + fixture.Checkout("tags/v1.0.0"); + fixture.BranchTo("support/v1.0.x", "support"); + fixture.Repository.MakeACommit("hotfix 1"); + fixture.Repository.ApplyTag("v1.0.1", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "hotfix 1"); + + fixture.BranchTo("hotfix/v1.0.2", "hotfix"); + fixture.Repository.MakeACommit("hotfix 2"); + + fixture.Checkout("support/v1.0.x"); + fixture.BranchTo("pull/2/merge", "pr-merge"); + fixture.MergeNoFF("hotfix/v1.0.2"); + + return fixture; + } + + private static RepositoryFixtureBase GivenIHaveALocalRepositoryWithAFeatureMergedInAPullRequestBranch() + { + var fixture = new EmptyRepositoryFixture(); + + fixture.Repository.MakeACommit("First commit"); + fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); + + fixture.Repository.MakeACommit("Merged PR 1: new feature"); + + fixture.BranchTo("feature/my-incredible-feature", "feature"); + fixture.Repository.MakeACommit("incredible feature"); + + fixture.Checkout(MainBranch); + fixture.BranchTo("pull/2/merge", "pr-merge"); + fixture.MergeNoFF("feature/my-incredible-feature"); + + return fixture; + } + + public static Config GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch() => new() + { + VersioningMode = VersioningMode.ContinuousDeployment, + Branches = new Dictionary + { + { MainBranch, new BranchConfig { Tag = "beta", Increment = IncrementStrategy.Minor } }, + { "pull-request", new BranchConfig { Tag = "alpha-pr", Increment = IncrementStrategy.Inherit } }, // Inherit is indeed the default + { "support", new BranchConfig { Tag = "beta" } } + } + }; } diff --git a/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs b/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs deleted file mode 100644 index 4f07829547..0000000000 --- a/src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs +++ /dev/null @@ -1,121 +0,0 @@ -using GitTools.Testing; -using GitVersion.Core.Tests.Helpers; -using GitVersion.Model.Configuration; -using GitVersion.VersionCalculation; -using LibGit2Sharp; -using NUnit.Framework; - -namespace GitVersion.Core.Tests.IntegrationTests; - -public class Issue3020FailedToInherit : TestBase -{ - private readonly Config config = new() - { - VersioningMode = VersioningMode.ContinuousDeployment, - Branches = new Dictionary - { - { MainBranch, new BranchConfig { Tag = "beta", Increment = IncrementStrategy.Minor } }, - { "pull-request", new BranchConfig { Tag = "alpha-pr", Increment = IncrementStrategy.Inherit } }, // Inherit is indeed the default - { "support", new BranchConfig { Tag = "beta" } } - } - }; - - [Test] - public void MergingHotFixIntoSupportLocalOnly() - { - using var fixture = PrepareLocalRepoForHotFix(); - - fixture.AssertFullSemver("1.0.2-alpha-pr0002.2", config); - - fixture.Repository.DumpGraph(); - } - - [Test] - public void MergingHotFixIntoSupportWithRemote() - { - using var fixture = PrepareLocalRepoForHotFix(); - - using var local = fixture.CloneRepository(); - local.Checkout("origin/hotfix/v1.0.2"); - local.BranchTo("hotfix/v1.0.2", "hotfix"); - local.Checkout("origin/support/v1.0.x"); - local.BranchTo("support/v1.0.x", "support"); - local.Checkout($"origin/{MainBranch}"); - local.BranchTo(MainBranch, MainBranch); - local.Checkout("pull/2/merge"); - - local.AssertFullSemver("1.0.2-alpha-pr0002.2", config); - - local.Repository.DumpGraph(); - } - - private static RepositoryFixtureBase PrepareLocalRepoForHotFix() - { - var fixture = new EmptyRepositoryFixture(); - - fixture.Repository.MakeACommit("First commit"); - fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); - - fixture.Repository.MakeACommit("Merged PR 1: new feature"); - - fixture.Checkout("tags/v1.0.0"); - fixture.BranchTo("support/v1.0.x", "support"); - fixture.Repository.MakeACommit("hotfix 1"); - fixture.Repository.ApplyTag("v1.0.1", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "hotfix 1"); - - fixture.BranchTo("hotfix/v1.0.2", "hotfix"); - fixture.Repository.MakeACommit("hotfix 2"); - - fixture.Checkout("support/v1.0.x"); - fixture.BranchTo("pull/2/merge", "pr-merge"); - fixture.MergeNoFF("hotfix/v1.0.2"); - - return fixture; - } - - [Test] - public void MergingFeatureIntoMainLocalOnly() - { - using var fixture = PrepareLocalRepoForFeature(); - - fixture.AssertFullSemver("1.1.0-alpha-pr0002.3", config); - - fixture.Repository.DumpGraph(); - } - - [Test] - public void MergingFeatureIntoMainWithRemote() - { - using var fixture = PrepareLocalRepoForFeature(); - - using var local = fixture.CloneRepository(); - local.Checkout("origin/feature/my-incredible-feature"); - local.BranchTo("feature/my-incredible-feature", "feature"); - local.Checkout($"origin/{MainBranch}"); - local.BranchTo(MainBranch, MainBranch); - local.Checkout("pull/2/merge"); - - local.AssertFullSemver("1.1.0-alpha-pr0002.3", config); - - local.Repository.DumpGraph(); - } - - private static RepositoryFixtureBase PrepareLocalRepoForFeature() - { - var fixture = new EmptyRepositoryFixture(); - - fixture.Repository.MakeACommit("First commit"); - fixture.Repository.ApplyTag("v1.0.0", new Signature("Michael Denny", "micdenny@gmail.com", DateTimeOffset.Now), "Release v1.0.0"); - - fixture.Repository.MakeACommit("Merged PR 1: new feature"); - - fixture.BranchTo("feature/my-incredible-feature", "feature"); - fixture.Repository.MakeACommit("incredible feature"); - - fixture.Checkout(MainBranch); - fixture.BranchTo("pull/2/merge", "pr-merge"); - fixture.MergeNoFF("feature/my-incredible-feature"); - - return fixture; - } -} From 059436a84695d62fabe59bff6ecf809a62c7b5bf Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 13 Sep 2022 14:30:20 +0200 Subject: [PATCH 7/8] fix code style --- .../IntegrationTests/HotfixBranchScenarios.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs index 4abd66fbbf..52a859087e 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -230,7 +230,7 @@ public void FeatureOnHotfixFeatureBranchNotDeleted() public void MergingHotFixIntoSupportLocalOnly() { var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); - + using var fixture = GivenIHaveALocalRepositoryWithAnHotFixMergedInAPullRequestBranch(); fixture.AssertFullSemver("1.0.2-alpha-pr0002.2", config); @@ -242,7 +242,7 @@ public void MergingHotFixIntoSupportLocalOnly() public void MergingHotFixIntoSupportWithRemote() { var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); - + using var fixture = GivenIHaveALocalRepositoryWithAnHotFixMergedInAPullRequestBranch(); using var local = fixture.CloneRepository(); @@ -263,7 +263,7 @@ public void MergingHotFixIntoSupportWithRemote() public void MergingFeatureIntoMainLocalOnly() { var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); - + using var fixture = GivenIHaveALocalRepositoryWithAFeatureMergedInAPullRequestBranch(); fixture.AssertFullSemver("1.1.0-alpha-pr0002.3", config); @@ -275,7 +275,7 @@ public void MergingFeatureIntoMainLocalOnly() public void MergingFeatureIntoMainWithRemote() { var config = GivenIHaveContinuousDeploymentConfigurationWithAMinorIncrementStrategyForMainBranch(); - + using var fixture = GivenIHaveALocalRepositoryWithAFeatureMergedInAPullRequestBranch(); using var local = fixture.CloneRepository(); From 0fec73e5797f1d47b6f126cea407c6d6ea37c2cb Mon Sep 17 00:00:00 2001 From: Michael Denny Date: Tue, 20 Sep 2022 11:06:48 +0200 Subject: [PATCH 8/8] specify the default parameter only on the interface level not on the implementation --- src/GitVersion.Core/Core/MergeCommitFinder.cs | 2 +- src/GitVersion.Core/Core/RepositoryStore.cs | 2 +- src/GitVersion.Core/PublicAPI.Shipped.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core/Core/MergeCommitFinder.cs b/src/GitVersion.Core/Core/MergeCommitFinder.cs index 20e496f6a3..12b81c1631 100644 --- a/src/GitVersion.Core/Core/MergeCommitFinder.cs +++ b/src/GitVersion.Core/Core/MergeCommitFinder.cs @@ -16,7 +16,7 @@ public MergeCommitFinder(RepositoryStore repositoryStore, Config configuration, { this.repositoryStore = repositoryStore.NotNull(); this.configuration = configuration.NotNull(); - this.excludedBranches = repositoryStore.ExcludingBranches(excludedBranches.NotNull()); + this.excludedBranches = repositoryStore.ExcludingBranches(excludedBranches.NotNull(), excludeRemotes: false); this.log = log.NotNull(); } diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index a3dfa44f49..ef74dee1ce 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -166,7 +166,7 @@ public IEnumerable GetExcludedInheritBranches(Config configuration) public IEnumerable GetReleaseBranches(IEnumerable> releaseBranchConfig) => this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig)); - public IEnumerable ExcludingBranches(IEnumerable branchesToExclude, bool excludeRemotes = false) + public IEnumerable ExcludingBranches(IEnumerable branchesToExclude, bool excludeRemotes) { var branches = this.repository.Branches.ExcludeBranches(branchesToExclude); if (excludeRemotes) diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index b7671bf2fd..a5a36aeb2b 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -844,7 +844,7 @@ GitVersion.RepositoryInfo.TargetBranch -> string? GitVersion.RepositoryInfo.TargetUrl -> string? GitVersion.RepositoryStore GitVersion.RepositoryStore.DetermineIncrementedField(GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.GitVersionContext! context) -> GitVersion.VersionField? -GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable! +GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable! branchesToExclude, bool excludeRemotes) -> System.Collections.Generic.IEnumerable! GitVersion.RepositoryStore.FindBranch(string? branchName) -> GitVersion.IBranch? GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(GitVersion.IBranch? branch, GitVersion.Model.Configuration.Config! configuration, params GitVersion.IBranch![]! excludedBranches) -> GitVersion.BranchCommit GitVersion.RepositoryStore.FindMainBranch(GitVersion.Model.Configuration.Config! configuration) -> GitVersion.IBranch?