Skip to content

Commit 20c3c2a

Browse files
committed
Remove TrunkBasedVersionCalculator and fix IsMatchForBranchSpecificLabel
1 parent 7042e5f commit 20c3c2a

File tree

9 files changed

+26
-34
lines changed

9 files changed

+26
-34
lines changed

src/GitVersion.Core/SemVer/SemanticVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SemanticVersion : IFormattable, IComparable<SemanticVersion>, IEqua
3333
public bool IsLabeledWith(string value) => PreReleaseTag.HasTag() && PreReleaseTag.Name.IsEquivalentTo(value);
3434

3535
public bool IsMatchForBranchSpecificLabel(string? value)
36-
=> PreReleaseTag.Name.Length == 0 || value is null || IsLabeledWith(value);
36+
=> (PreReleaseTag.Name == string.Empty && PreReleaseTag.Number is null) || value is null || IsLabeledWith(value);
3737

3838
public SemanticVersion(long major = 0, long minor = 0, long patch = 0)
3939
{

src/GitVersion.Core/VersionCalculation/TrunkBased/NonTrunk/MergeCommitOnNonTrunkBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public virtual IEnumerable<BaseVersionV2> GetIncrements(TrunkBasedIteration iter
99
{
1010
var baseVersion = TrunkBasedVersionStrategy.DetermineBaseVersionRecursive(
1111
iteration: commit.ChildIteration!,
12-
targetLabelBS: context.TargetLabel,
12+
targetLabel: context.TargetLabel,
1313
taggedSemanticVersions: context.TaggedSemanticVersions
1414
);
1515

src/GitVersion.Core/VersionCalculation/TrunkBased/Trunk/MergeCommitOnTrunkBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public virtual IEnumerable<BaseVersionV2> GetIncrements(TrunkBasedIteration iter
1111
{
1212
var baseVersion = TrunkBasedVersionStrategy.DetermineBaseVersionRecursive(
1313
iteration: commit.ChildIteration!,
14-
targetLabelBS: context.TargetLabel,
14+
targetLabel: context.TargetLabel,
1515
taggedSemanticVersions: context.TaggedSemanticVersions
1616
);
1717

src/GitVersion.Core/VersionCalculation/TrunkBased/TrunkBasedVersionStrategy.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ private bool IterateOverCommitsRecursive(IEnumerable<ICommit> commitsInReverseOr
103103
{
104104
commit.AddSemanticVersions(values);
105105

106-
var labelBS = targetLabel ?? configuration.GetBranchSpecificLabel(branchName, null);
106+
var label = targetLabel ?? configuration.GetBranchSpecificLabel(branchName, null);
107107
foreach (var semanticVersion in values)
108108
{
109-
if (semanticVersion.IsMatchForBranchSpecificLabel(labelBS)) return true;
109+
if (semanticVersion.IsMatchForBranchSpecificLabel(label)) return true;
110110
}
111111
}
112112

@@ -222,18 +222,18 @@ private IReadOnlyDictionary<ICommit, EffectiveBranchConfiguration> GetCommitsWas
222222
}
223223

224224
private static BaseVersionV2 DetermineBaseVersion(
225-
TrunkBasedIteration iteration, string? targetLabelBS,
225+
TrunkBasedIteration iteration, string? targetLabel,
226226
IReadOnlyDictionary<string, HashSet<SemanticVersion>> taggedSemanticVersions
227-
) => DetermineBaseVersionRecursive(iteration, targetLabelBS, taggedSemanticVersions);
227+
) => DetermineBaseVersionRecursive(iteration, targetLabel, taggedSemanticVersions);
228228

229229
internal static BaseVersionV2 DetermineBaseVersionRecursive(
230-
TrunkBasedIteration iteration, string? targetLabelBS,
230+
TrunkBasedIteration iteration, string? targetLabel,
231231
IReadOnlyDictionary<string, HashSet<SemanticVersion>> taggedSemanticVersions)
232232
{
233233
iteration.NotNull();
234234
taggedSemanticVersions.NotNull();
235235

236-
var incrementSteps = GetIncrementSteps(iteration, targetLabelBS, taggedSemanticVersions).ToArray();
236+
var incrementSteps = GetIncrementSteps(iteration, targetLabel, taggedSemanticVersions).ToArray();
237237

238238
var semanticVersion = SemanticVersion.Empty;
239239

@@ -277,11 +277,11 @@ internal static BaseVersionV2 DetermineBaseVersionRecursive(
277277
}
278278

279279
private static IEnumerable<BaseVersionV2> GetIncrementSteps(TrunkBasedIteration iteration,
280-
string? targetLabelBS, IReadOnlyDictionary<string, HashSet<SemanticVersion>> taggedSemanticVersions)
280+
string? targetLabel, IReadOnlyDictionary<string, HashSet<SemanticVersion>> taggedSemanticVersions)
281281
{
282282
TrunkBasedContext context = new(taggedSemanticVersions)
283283
{
284-
TargetLabel = targetLabelBS,
284+
TargetLabel = targetLabel,
285285
};
286286

287287
foreach (var commit in iteration.Commits)

src/GitVersion.Core/VersionCalculation/VersionCalculationModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public void RegisterTypes(IServiceCollection services)
1111

1212
services.AddSingleton<IVariableProvider, VariableProvider>();
1313
services.AddSingleton<IVersionModeCalculator, MainlineVersionCalculator>();
14-
services.AddSingleton<IVersionModeCalculator, TrunkBasedVersionCalculator>();
1514
services.AddSingleton<IVersionModeCalculator, ContinuousDeploymentVersionCalculator>();
1615
services.AddSingleton<IVersionModeCalculator, ContinuousDeliveryVersionCalculator>();
1716
services.AddSingleton<IVersionModeCalculator, ManualDeploymentVersionCalculator>();

src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ public SemanticVersion Calculate(NextVersion nextVersion)
1414
{
1515
using (this.log.IndentLog("Using manual deployment workflow to calculate the incremented version."))
1616
{
17-
var preReleaseTag = nextVersion.IncrementedVersion.PreReleaseTag;
18-
if (!preReleaseTag.HasTag() || !preReleaseTag.Number.HasValue)
19-
{
20-
throw new WarningException("Manual deployment requires a pre-release tag.");
21-
}
22-
2317
return CalculateInternal(nextVersion);
2418
}
2519
}

src/GitVersion.Core/VersionCalculation/VersionCalculators/NonTrunkBasedVersionCalculatorBase.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using GitVersion.Common;
2-
using GitVersion.Configuration;
32
using GitVersion.Extensions;
43
using GitVersion.Logging;
54

@@ -22,15 +21,12 @@ public NonTrunkBasedVersionCalculatorBase(ILog log, IRepositoryStore repositoryS
2221

2322
protected bool ShouldTakeIncrementedVersion(NextVersion nextVersion)
2423
{
25-
var label = nextVersion.Configuration.GetBranchSpecificLabel(
26-
Context.CurrentBranch.Name, nextVersion.BaseVersion.BranchNameOverride
27-
);
24+
nextVersion.NotNull();
2825

29-
////
3026
// TODO: We need to decide whether or not to calculate the upcoming semantic version or the previous one because of tagging. Actually this should be part of the branch configuration system.
31-
return Context.CurrentCommit?.Sha != nextVersion.BaseVersion.BaseVersionSource?.Sha
32-
|| Context.CurrentCommitTaggedVersion == null
33-
|| !Context.CurrentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label);
27+
return Context.CurrentCommit.Sha != nextVersion.BaseVersion.BaseVersionSource?.Sha
28+
|| Context.CurrentCommitTaggedVersion is null
29+
|| nextVersion.BaseVersion.SemanticVersion != Context.CurrentCommitTaggedVersion;
3430
//
3531
}
3632

src/GitVersion.Core/VersionCalculation/VersionCalculators/TrunkBasedVersionCalculator.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ public void MergeNoFF(string mergeSource)
118118
Repository.MergeNoFF(mergeSource, Generate.SignatureNow());
119119
}
120120

121+
public void MergeTo(string branchName, bool removeBranchAfterMerging = false)
122+
{
123+
string mergeSource = Repository.Head.FriendlyName;
124+
Checkout(branchName);
125+
MergeNoFF(mergeSource);
126+
if (removeBranchAfterMerging)
127+
{
128+
Remove(mergeSource);
129+
}
130+
}
131+
121132
/// <summary>
122133
/// Clones the repository managed by this fixture into another LocalRepositoryFixture
123134
/// </summary>

0 commit comments

Comments
 (0)