Skip to content

Commit 77523fe

Browse files
committed
Fix integration test
1 parent ddb87d1 commit 77523fe

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void GitFlowMajorRelease()
202202
fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/2.0.0");
203203

204204
fixture.Checkout(MainBranch);
205-
fixture.AssertFullSemver("2.0.0-4");
205+
fixture.AssertFullSemver("2.0.0-0");
206206
fixture.ApplyTag("2.0.0");
207207
fixture.AssertFullSemver("2.0.0");
208208

@@ -291,7 +291,7 @@ public void GitFlowSupportMinorRelease()
291291
fixture.MergeNoFF("release/1.4.0");
292292
fixture.SequenceDiagram.Destroy("release/1.4.0");
293293
fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/1.4.0");
294-
fixture.AssertFullSemver("1.4.0-4");
294+
fixture.AssertFullSemver("1.4.0-0");
295295
fixture.ApplyTag("1.4.0");
296296
fixture.AssertFullSemver("1.4.0");
297297
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
@@ -392,7 +392,7 @@ public void GitHubFlowMajorRelease()
392392
fixture.SequenceDiagram.Destroy("release/2.0.0");
393393
fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/2.0.0");
394394

395-
fixture.AssertFullSemver("2.0.0-4");
395+
fixture.AssertFullSemver("2.0.0-0");
396396
fixture.ApplyTag("2.0.0");
397397
fixture.AssertFullSemver("2.0.0");
398398
fixture.MakeACommit();

src/GitVersion.Core.Tests/IntegrationTests/FallbackVersionStrategyScenarios.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,35 @@ public void TakeTheLatestCommitAsBaseVersion(bool mode)
9393
// ✅ succeeds as expected
9494
fixture.AssertFullSemver("1.0.0-1+1", configuration);
9595
}
96+
97+
[TestCase(false, "1.0.0-1+4")]
98+
[TestCase(true, "1.0.0-1+2")]
99+
public void TakeTheCommitBranchedFromAsBaseVersionWhenTracksReleaseBranchesIsTrue(
100+
bool tracksReleaseBranches, string version)
101+
{
102+
var configuration = ConfigurationBuilder
103+
.WithBranch("main", _ => _
104+
.WithIncrement(IncrementStrategy.Major)
105+
.WithTrackMergeTarget(false)
106+
.WithTracksReleaseBranches(tracksReleaseBranches)
107+
).Build();
108+
109+
using EmptyRepositoryFixture fixture = new("main");
110+
111+
fixture.MakeACommit("A");
112+
fixture.MakeACommit("B");
113+
fixture.BranchTo("release/foo");
114+
fixture.Checkout("main");
115+
fixture.MakeACommit("C");
116+
fixture.Checkout("release/foo");
117+
fixture.MakeACommit("D");
118+
fixture.ApplyTag("0.0.0");
119+
fixture.Checkout("main");
120+
fixture.MakeACommit("D");
121+
122+
// ✅ succeeds as expected
123+
fixture.AssertFullSemver(version, configuration);
124+
125+
fixture.Repository.DumpGraph();
126+
}
96127
}

src/GitVersion.Core/Core/EffectiveConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static TaggedSemanticVersions GetTaggedSemanticVersion(this EffectiveConf
1616
taggedSemanticVersion |= TaggedSemanticVersions.OfMergeTargets;
1717
}
1818

19-
if (effectiveConfiguration.TrackMergeTarget)
19+
if (effectiveConfiguration.TracksReleaseBranches)
2020
{
2121
taggedSemanticVersion |= TaggedSemanticVersions.OfReleaseBranches;
2222
}

src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ private IEnumerable<BaseVersion> GetBaseVersionsInternal(EffectiveBranchConfigur
4040
).SelectMany(elements => elements).Distinct().ToArray();
4141

4242
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
43+
var semanticVersionsWithTag = taggedSemanticVersionService.GetTaggedSemanticVersions(
44+
branch: Context.CurrentBranch,
45+
configuration: Context.Configuration,
46+
label: label,
47+
notOlderThan: Context.CurrentCommit.When,
48+
taggedSemanticVersion: configuration.Value.GetTaggedSemanticVersion()
49+
).SelectMany(elements => elements).Distinct().ToArray();
4350

44-
var maxTaggedSemanticVersion = taggedSemanticVersions
45-
.Where(element => !element.Value.IsMatchForBranchSpecificLabel(label)).Max();
46-
47-
foreach (var semanticVersionWithTag
48-
in taggedSemanticVersions.Where(element => element.Value.IsMatchForBranchSpecificLabel(label)))
51+
foreach (var semanticVersionWithTag in semanticVersionsWithTag)
4952
{
5053
var baseVersionSource = semanticVersionWithTag.Tag.Commit;
5154
var increment = incrementStrategyFinder.DetermineIncrementedField(
@@ -62,8 +65,7 @@ in taggedSemanticVersions.Where(element => element.Value.IsMatchForBranchSpecifi
6265
{
6366
Increment = increment,
6467
ForceIncrement = false,
65-
Label = label,
66-
AlternativeSemanticVersion = maxTaggedSemanticVersion?.Value
68+
Label = label
6769
}
6870
};
6971
}

0 commit comments

Comments
 (0)