Skip to content

Fix bug on PR when target has two possibilities #423

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

Merged
merged 1 commit into from
Apr 23, 2015
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