diff --git a/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs b/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs index 87af5373be..bc9a817074 100644 --- a/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs +++ b/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs @@ -73,6 +73,24 @@ public void CanCalculatePullRequestChangesInheritingConfigFromRemoteRepo() } } + [Test] + public void CanCalculatePullRequestChangesWhenThereAreMultipleMergeCandidates() + { + using (var fixture = new EmptyRepositoryFixture(new Config())) + { + fixture.Repository.MakeATaggedCommit("0.1.0"); + fixture.Repository.CreateBranch("develop").Checkout(); + fixture.Repository.MakeACommit(); + fixture.Repository.CreateBranch("copyOfDevelop").Checkout(); + fixture.Repository.CreateBranch("feature/Foo").Checkout(); + fixture.Repository.MakeACommit(); + + fixture.Repository.CreatePullRequest("feature/Foo", "develop"); + + fixture.AssertFullSemver("0.2.0-PullRequest.2+3"); + } + } + [Test] public void CalculatesCorrectVersionAfterReleaseBranchMergedToMaster() { diff --git a/GitVersionCore/BranchConfigurationCalculator.cs b/GitVersionCore/BranchConfigurationCalculator.cs index 7955cece50..e414e96181 100644 --- a/GitVersionCore/BranchConfigurationCalculator.cs +++ b/GitVersionCore/BranchConfigurationCalculator.cs @@ -57,7 +57,15 @@ static KeyValuePair InheritBranchConfiguration( } else { - currentBranch = repository.Branches.SingleOrDefault(b => !b.IsRemote && b.Tip == parents[0]) ?? currentBranch; + var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList(); + if (possibleTargetBranches.Count() > 1) + { + currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name == "master") ?? possibleTargetBranches.First(); + } + else + { + currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch; + } } Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");