Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
10 changes: 9 additions & 1 deletion GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ static KeyValuePair<string, BranchConfig> 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");
Expand Down