Skip to content

Commit 9dc2a92

Browse files
committed
Create TaggedSemanticVersionService class
1 parent 6012da7 commit 9dc2a92

14 files changed

+405
-248
lines changed

src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public static GitVersionVariables GetVersion(this RepositoryFixtureBase fixture,
6161
{
6262
repository ??= fixture.Repository;
6363
configuration ??= GitFlowConfigurationBuilder.New.Build();
64-
Console.WriteLine("---------");
6564

6665
var overrideConfiguration = new Dictionary<object, object?>();
6766
var options = Options.Create(new GitVersionOptions

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-0");
205+
fixture.AssertFullSemver("2.0.0-4");
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-0");
294+
fixture.AssertFullSemver("1.4.0-4");
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-0");
395+
fixture.AssertFullSemver("2.0.0-4");
396396
fixture.ApplyTag("2.0.0");
397397
fixture.AssertFullSemver("2.0.0");
398398
fixture.MakeACommit();

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,4 @@ public void TakeTheLatestCommitAsBaseVersion(bool mode)
9393
// ✅ succeeds as expected
9494
fixture.AssertFullSemver("1.0.0-1+1", configuration);
9595
}
96-
97-
[Test]
98-
public void TakeTheCommitBranchedFromAsBaseVersion()
99-
{
100-
var configuration = ConfigurationBuilder
101-
.WithBranch("main", _ => _
102-
.WithIncrement(IncrementStrategy.Major)
103-
.WithTrackMergeTarget(false)
104-
.WithTracksReleaseBranches(true)
105-
).Build();
106-
107-
using EmptyRepositoryFixture fixture = new("main");
108-
109-
fixture.MakeACommit("A");
110-
fixture.MakeACommit("B");
111-
fixture.BranchTo("release/foo");
112-
fixture.Checkout("main");
113-
fixture.MakeACommit("C");
114-
fixture.Checkout("release/foo");
115-
fixture.MakeACommit("D");
116-
fixture.ApplyTag("0.0.0");
117-
fixture.Checkout("main");
118-
fixture.MakeACommit("D");
119-
120-
// ✅ succeeds as expected
121-
fixture.AssertFullSemver("1.0.0-1+2", configuration);
122-
123-
fixture.Repository.DumpGraph();
124-
}
12596
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using GitVersion.Configuration;
2+
using GitVersion.Extensions;
3+
4+
namespace GitVersion.Core;
5+
6+
internal static class EffectiveConfigurationExtensions
7+
{
8+
public static TaggedSemanticVersions GetTaggedSemanticVersion(this EffectiveConfiguration effectiveConfiguration)
9+
{
10+
effectiveConfiguration.NotNull();
11+
12+
TaggedSemanticVersions taggedSemanticVersion = TaggedSemanticVersions.OfBranch;
13+
14+
if (effectiveConfiguration.TrackMergeTarget)
15+
{
16+
taggedSemanticVersion |= TaggedSemanticVersions.OfMergeTargets;
17+
}
18+
19+
if (effectiveConfiguration.TrackMergeTarget)
20+
{
21+
taggedSemanticVersion |= TaggedSemanticVersions.OfReleaseBranches;
22+
}
23+
24+
if (!effectiveConfiguration.IsMainBranch && !effectiveConfiguration.IsReleaseBranch)
25+
{
26+
taggedSemanticVersion |= TaggedSemanticVersions.OfMainBranches;
27+
}
28+
return taggedSemanticVersion;
29+
}
30+
}

src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ namespace GitVersion.Core;
55

66
internal interface ITaggedSemanticVersionRepository
77
{
8-
ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(
9-
IGitVersionConfiguration configuration,
10-
EffectiveConfiguration effectiveConfiguration,
11-
IBranch branch,
12-
string? label,
13-
DateTimeOffset? notOlderThan);
14-
158
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfBranch(
169
IBranch branch,
1710
string? tagPrefix,
@@ -24,18 +17,6 @@ ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
2417
SemanticVersionFormat format,
2518
IIgnoreConfiguration ignore);
2619

27-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
28-
IGitVersionConfiguration configuration,
29-
string? tagPrefix,
30-
SemanticVersionFormat format,
31-
params IBranch[] excludeBranches);
32-
33-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranches(
34-
IGitVersionConfiguration configuration,
35-
string? tagPrefix,
36-
SemanticVersionFormat format,
37-
params IBranch[] excludeBranches);
38-
3920
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(
4021
string? tagPrefix, SemanticVersionFormat format, IIgnoreConfiguration ignore);
4122
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using GitVersion.Configuration;
2+
using GitVersion.Git;
3+
4+
namespace GitVersion.Core;
5+
6+
internal interface ITaggedSemanticVersionService
7+
{
8+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(
9+
IBranch branch,
10+
IGitVersionConfiguration configuration,
11+
string? label,
12+
DateTimeOffset? notOlderThan,
13+
TaggedSemanticVersions taggedSemanticVersion);
14+
15+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfBranch(
16+
IBranch branch,
17+
string? tagPrefix,
18+
SemanticVersionFormat format,
19+
IIgnoreConfiguration ignore,
20+
string? label = null,
21+
DateTimeOffset? notOlderThan = null);
22+
23+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
24+
IBranch branch,
25+
string? tagPrefix,
26+
SemanticVersionFormat format,
27+
IIgnoreConfiguration ignore,
28+
string? label = null,
29+
DateTimeOffset? notOlderThan = null);
30+
31+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
32+
IGitVersionConfiguration configuration,
33+
DateTimeOffset? notOlderThan = null,
34+
string? label = null,
35+
params IBranch[] excludeBranches);
36+
37+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranches(
38+
IGitVersionConfiguration configuration,
39+
DateTimeOffset? notOlderThan = null,
40+
string? label = null,
41+
params IBranch[] excludeBranches);
42+
}

0 commit comments

Comments
 (0)