Skip to content

Commit 7786c55

Browse files
committed
Fixed develop being reintegrated into long running feature branch. Fixes #568
1 parent 509caa7 commit 7786c55

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,32 @@ public void WhenTwoFeatureBranchPointToTheSameCommit()
128128
fixture.AssertFullSemver("0.1.0-feature2.1+1");
129129
}
130130
}
131+
132+
[Test]
133+
public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMasterAreEqual()
134+
{
135+
using (var fixture = new EmptyRepositoryFixture(new Config() { VersioningMode = VersioningMode.ContinuousDeployment }))
136+
{
137+
fixture.Repository.MakeATaggedCommit("v1.0.0");
138+
139+
fixture.Repository.CreateBranch("develop");
140+
fixture.Repository.Checkout("develop");
141+
142+
fixture.Repository.CreateBranch("feature/longrunning");
143+
fixture.Repository.Checkout("feature/longrunning");
144+
fixture.Repository.MakeACommit();
145+
146+
fixture.Repository.Checkout("develop");
147+
fixture.Repository.MakeACommit();
148+
149+
fixture.Repository.Checkout("master");
150+
fixture.Repository.Merge(fixture.Repository.FindBranch("develop"), SignatureBuilder.SignatureNow());
151+
fixture.Repository.ApplyTag("v1.1.0");
152+
153+
fixture.Repository.Checkout("feature/longrunning");
154+
fixture.Repository.Merge(fixture.Repository.FindBranch("develop"), SignatureBuilder.SignatureNow());
155+
156+
fixture.AssertFullSemver("1.2.0-longrunning.2");
157+
}
158+
}
131159
}

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
4949
var parentCount = currentCommit.Parents.Count();
5050
if (parentCount == 2)
5151
{
52-
var parents = currentCommit.Parents.ToArray();
53-
var branch = repository.Branches.SingleOrDefault(b => !b.IsRemote && b.Tip == parents[1]);
54-
if (branch != null)
55-
{
56-
excludedBranches = new[]
57-
{
58-
currentBranch,
59-
branch
60-
};
61-
currentBranch = branch;
62-
}
63-
else
64-
{
65-
var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList();
66-
if (possibleTargetBranches.Count() > 1)
67-
{
68-
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name == "master") ?? possibleTargetBranches.First();
69-
}
70-
else
71-
{
72-
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
73-
}
74-
}
75-
76-
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");
52+
excludedBranches = CalculateWhenMultipleParents(repository, currentCommit, ref currentBranch, excludedBranches);
7753
}
7854
if (excludedInheritBranches == null)
7955
{
@@ -142,5 +118,41 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
142118
});
143119
}
144120
}
121+
122+
static Branch[] CalculateWhenMultipleParents(IRepository repository, Commit currentCommit, ref Branch currentBranch, Branch[] excludedBranches)
123+
{
124+
var parents = currentCommit.Parents.ToArray();
125+
var branches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[1]).ToList();
126+
if (branches.Count == 1)
127+
{
128+
var branch = branches[0];
129+
excludedBranches = new[]
130+
{
131+
currentBranch,
132+
branch
133+
};
134+
currentBranch = branch;
135+
}
136+
else if (branches.Count > 1)
137+
{
138+
currentBranch = branches.FirstOrDefault(b => b.Name == "master") ?? branches.First();
139+
}
140+
else
141+
{
142+
var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList();
143+
if (possibleTargetBranches.Count > 1)
144+
{
145+
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name == "master") ?? possibleTargetBranches.First();
146+
}
147+
else
148+
{
149+
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
150+
}
151+
}
152+
153+
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");
154+
155+
return excludedBranches;
156+
}
145157
}
146158
}

0 commit comments

Comments
 (0)