From ce87323a52445a5602f5e52e74dfc4fe738c5b6f Mon Sep 17 00:00:00 2001 From: Yannis Guedel Date: Thu, 23 Apr 2015 17:18:52 +0200 Subject: [PATCH] Fix bug on PR when target has two possibilities This PR fixes a bug on pull-request builds when there are two possibilities which branch the pull-reuqest targets. --- .../IntegrationTests/PullRequestScenarios.cs | 18 ++++++++++++++++++ .../BranchConfigurationCalculator.cs | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) 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");