Skip to content

Commit aa1e687

Browse files
committed
Merge pull request #423 from unic/fixTCBuild
Fix bug on PR when target has two possibilities
2 parents fe1063f + ce87323 commit aa1e687

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public void CanCalculatePullRequestChangesInheritingConfigFromRemoteRepo()
7373
}
7474
}
7575

76+
[Test]
77+
public void CanCalculatePullRequestChangesWhenThereAreMultipleMergeCandidates()
78+
{
79+
using (var fixture = new EmptyRepositoryFixture(new Config()))
80+
{
81+
fixture.Repository.MakeATaggedCommit("0.1.0");
82+
fixture.Repository.CreateBranch("develop").Checkout();
83+
fixture.Repository.MakeACommit();
84+
fixture.Repository.CreateBranch("copyOfDevelop").Checkout();
85+
fixture.Repository.CreateBranch("feature/Foo").Checkout();
86+
fixture.Repository.MakeACommit();
87+
88+
fixture.Repository.CreatePullRequest("feature/Foo", "develop");
89+
90+
fixture.AssertFullSemver("0.2.0-PullRequest.2+3");
91+
}
92+
}
93+
7694
[Test]
7795
public void CalculatesCorrectVersionAfterReleaseBranchMergedToMaster()
7896
{

GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
5757
}
5858
else
5959
{
60-
currentBranch = repository.Branches.SingleOrDefault(b => !b.IsRemote && b.Tip == parents[0]) ?? currentBranch;
60+
var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList();
61+
if (possibleTargetBranches.Count() > 1)
62+
{
63+
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name == "master") ?? possibleTargetBranches.First();
64+
}
65+
else
66+
{
67+
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
68+
}
6169
}
6270

6371
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");

0 commit comments

Comments
 (0)