Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closing pull request from hotfix to support failed to inherit Increment branch configuration #3196

Closed
wants to merge 8 commits into from
121 changes: 121 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/Issue3020FailedToInherit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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
micdenny marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly Config config = new()
{
VersioningMode = VersioningMode.ContinuousDeployment,
Branches = new Dictionary<string, BranchConfig>
{
{ 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", "[email protected]", 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", "[email protected]", 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", "[email protected]", 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
micdenny marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IRepositoryStore
IEnumerable<IBranch> GetBranchesForCommit(ICommit commit);
IEnumerable<IBranch> GetExcludedInheritBranches(Config configuration);
IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string, BranchConfig>> releaseBranchConfig);
IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude);
IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude, bool excludeRemotes = false);
IEnumerable<IBranch> GetBranchesContainingCommit(ICommit? commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false);
IDictionary<string, List<IBranch>> GetMainlineBranches(ICommit commit, Config configuration, IEnumerable<KeyValuePair<string, BranchConfig>>? mainlineBranchConfigs);

Expand Down
10 changes: 9 additions & 1 deletion src/GitVersion.Core/Core/RepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ public IEnumerable<IBranch> GetExcludedInheritBranches(Config configuration)
public IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string, BranchConfig>> releaseBranchConfig)
=> this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig));

public IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude) => this.repository.Branches.ExcludeBranches(branchesToExclude);
public IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude, bool excludeRemotes = false)
micdenny marked this conversation as resolved.
Show resolved Hide resolved
{
var branches = this.repository.Branches.ExcludeBranches(branchesToExclude);
if (excludeRemotes)
{
branches = branches.Where(b => !b.IsRemote);
}
return branches;
}

public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit? commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false)
{
Expand Down
1 change: 1 addition & 0 deletions src/GitVersion.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GitVersion.RepositoryStore.ExcludingBranches(System.Collections.Generic.IEnumerable<GitVersion.IBranch!>! branchesToExclude, bool excludeRemotes = false) -> System.Collections.Generic.IEnumerable<GitVersion.IBranch!>!
micdenny marked this conversation as resolved.
Show resolved Hide resolved