Skip to content

Commit 4f8d583

Browse files
authored
Merge pull request #4020 from HHobeck/feature/align-trunk-based-version-strategy-with-git-flow
Finalizing the configuration of GitFlow and GitHubFlow workflow and align with the Mainline version strategy
2 parents 943fc4c + 98b212b commit 4f8d583

File tree

14 files changed

+169
-128
lines changed

14 files changed

+169
-128
lines changed

BREAKING_CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
* The initialization wizard has been removed.
5757
* On the `develop`, `release` and `hotfix` branch the introduced branch related property `prevent-increment.when-current-commit-tagged` has been set to `false` to get the incremented instead of the tagged semantic version.
5858
* When setting the "ignore commits before" parameter to a future value, an exception will occur if no commits are found on the current branch. This behavior mimics that of an empty repository.
59+
* On the `GitFlow` workflow the increment property has been changed:
60+
* in branch `release` from `None` to `Minor` and
61+
* in branch `hotfix` from `None` to `Patch`
62+
* On the `GitHubFlow` workflow the increment property has been changed in branch `release` from `None` to `Patch`.
63+
* When creating a branch with name `hotfix/next` (by using the `GitFlow` workflow) or `release/next` (by the `GitHubFlow` workflow) the resulting version will yield to a patched version per default.
64+
* If you have a tag `1.0.0` on `main` and branch from `main` to `release/1.0.1` then the next version number will be `1.1.0` when using the `GitFlow` workflow. This behavior is expected (but different compared to the `GitHubFlow` workflow) because on the `GitFlow` workflow you have an addition branch configuration with name hotfix where `is-release-branch` is set to `true`. That means if you want `1.0.1` as a next version you need to branch to `hotfix/1.0.1` or `hotfix/next`. On the other hand if you use the `GitHubFlow` workflow the next version number will be `1.0.1` because the increment on the `release` branch is set to `Patch`.
5965
6066
## v5.0.0
6167

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
assembly-versioning-scheme: MajorMinorPatch
1+
workflow: GitFlow/v1
22
branches:
33
main:
44
label: beta

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

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -616,29 +616,13 @@ public void EnsureFeatureDevelopmentWithDevelopBranchFast(bool useTrunkBased)
616616

617617
fixture.BranchTo("feature/foo");
618618

619-
if (useTrunkBased)
620-
{
621-
// ❔ expected: "0.1.0-foo.1+0"
622-
fixture.AssertFullSemver("0.0.2-foo.1+0", configuration);
623-
}
624-
else
625-
{
626-
// ✅ succeeds as expected
627-
fixture.AssertFullSemver("0.1.0-foo.1+0", configuration);
628-
}
619+
// ✅ succeeds as expected
620+
fixture.AssertFullSemver("0.1.0-foo.1+0", configuration);
629621

630622
fixture.MakeACommit("B");
631623

632-
if (useTrunkBased)
633-
{
634-
// ❔ expected: "0.1.0-foo.1+1"
635-
fixture.AssertFullSemver("0.0.2-foo.1+1", configuration);
636-
}
637-
else
638-
{
639-
// ✅ succeeds as expected
640-
fixture.AssertFullSemver("0.1.0-foo.1+1", configuration);
641-
}
624+
// ✅ succeeds as expected
625+
fixture.AssertFullSemver("0.1.0-foo.1+1", configuration);
642626

643627
fixture.ApplyTag("0.1.0-foo.1");
644628

@@ -946,31 +930,15 @@ public void EnsureBugFixWithDevelopBranchFast(bool useTrunkBased)
946930
fixture.BranchTo("pull/2/merge");
947931
fixture.MergeNoFF("hotfix/foo");
948932

949-
if (useTrunkBased)
950-
{
951-
// ❔ expected: "0.1.0-PullRequest2.4"
952-
fixture.AssertFullSemver("0.0.2-PullRequest2.4", configuration);
953-
}
954-
else
955-
{
956-
// ✅ succeeds as expected
957-
fixture.AssertFullSemver("0.1.0-PullRequest2.4", configuration);
958-
}
933+
// ✅ succeeds as expected
934+
fixture.AssertFullSemver("0.1.0-PullRequest2.4", configuration);
959935

960936
fixture.Checkout("main");
961937
fixture.BranchTo("pull/3/merge");
962938
fixture.MergeNoFF("hotfix/foo");
963939

964-
if (useTrunkBased)
965-
{
966-
// ✅ succeeds as expected
967-
fixture.AssertFullSemver("0.0.2-PullRequest3.4", configuration);
968-
}
969-
else
970-
{
971-
// ❔ expected: "0.0.2-PullRequest3.4"
972-
fixture.AssertFullSemver("0.1.0-PullRequest3.4", configuration);
973-
}
940+
// ❔ expected: "0.0.2-PullRequest3.4"
941+
fixture.AssertFullSemver("0.1.0-PullRequest3.4", configuration);
974942

975943
fixture.Checkout("hotfix/foo");
976944
fixture.MergeTo("main", removeBranchAfterMerging: true);
@@ -985,26 +953,6 @@ public void EnsureBugFixWithDevelopBranchFast(bool useTrunkBased)
985953
fixture.AssertFullSemver("0.0.3-1", configuration);
986954
}
987955

988-
[Test]
989-
public void JustATest()
990-
{
991-
var configuration = configurationBuilder.WithVersionStrategy(VersionStrategies.TrunkBased).Build();
992-
993-
using var fixture = new EmptyRepositoryFixture("main");
994-
995-
fixture.MakeACommit("A");
996-
997-
// ✅ succeeds as expected
998-
fixture.AssertFullSemver("0.0.1-1", configuration);
999-
1000-
fixture.ApplyTag("0.1.0");
1001-
1002-
for (int i = 0; i < 10; i++) fixture.MakeACommit();
1003-
1004-
// ✅ succeeds as expected
1005-
fixture.AssertFullSemver("0.1.10-1", configuration);
1006-
}
1007-
1008956
[TestCase(false)]
1009957
[TestCase(true)]
1010958
public void EnsureFeatureDevelopmentWithReleaseNextBranch(bool useTrunkBased)

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,4 +1364,42 @@ public void UnversionedHotfix()
13641364

13651365
fixture.AssertFullSemver("1.2.1-3", configuration);
13661366
}
1367+
1368+
[Test]
1369+
public void AlternativeSemanticVersionsShouldBeConsidered()
1370+
{
1371+
var configuration = GitFlowConfigurationBuilder.New.Build();
1372+
1373+
using EmptyRepositoryFixture fixture = new("main");
1374+
1375+
fixture.MakeACommit("A");
1376+
fixture.MakeATaggedCommit("4.0.0-beta.14");
1377+
fixture.MakeACommit("B");
1378+
1379+
fixture.AssertFullSemver("4.0.0-3", configuration);
1380+
}
1381+
1382+
[TestCase(null, "6.0.0-beta.6")]
1383+
[TestCase("beta", "6.0.0-beta.21")]
1384+
public void AlternativeSemanticVersionsShouldBeConsidered(string? labelOnMain, string version)
1385+
{
1386+
var configuration = GitFlowConfigurationBuilder.New
1387+
.WithLabel(null)
1388+
.WithBranch("main", _ => _.WithLabel(labelOnMain))
1389+
.Build();
1390+
1391+
using EmptyRepositoryFixture fixture = new("main");
1392+
1393+
fixture.MakeATaggedCommit("1.0.0");
1394+
fixture.MakeATaggedCommit("4.0.0-beta.14");
1395+
fixture.MakeACommit("A");
1396+
fixture.MakeATaggedCommit("6.0.0-alpha.1");
1397+
fixture.MakeATaggedCommit("6.0.0-alpha.2");
1398+
fixture.MakeATaggedCommit("6.0.0-alpha.3");
1399+
fixture.MakeACommit("B");
1400+
fixture.MakeATaggedCommit("6.0.0-beta.5");
1401+
fixture.MakeACommit("C");
1402+
1403+
fixture.AssertFullSemver(version, configuration);
1404+
}
13671405
}

src/GitVersion.Core/Git/ReferenceName.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static bool TryParse([NotNullWhen(true)] out ReferenceName? value, string
5454
value = new(canonicalName);
5555
}
5656

57-
return value != null;
57+
return value is not null;
5858
}
5959

6060
public static ReferenceName FromBranchName(string branchName)
@@ -77,6 +77,15 @@ public static ReferenceName FromBranchName(string branchName)
7777
public override int GetHashCode() => equalityHelper.GetHashCode(this);
7878
public override string ToString() => Friendly;
7979

80+
public static bool operator ==(ReferenceName? left, ReferenceName? right)
81+
{
82+
if (ReferenceEquals(left, right)) return true;
83+
if (left is null || right is null) return false;
84+
return left.Equals(right);
85+
}
86+
87+
public static bool operator !=(ReferenceName? left, ReferenceName? right) => !(left == right);
88+
8089
public bool TryGetSemanticVersion([NotNullWhen(true)] out (SemanticVersion Value, string? Name) result,
8190
Regex versionPatternRegex,
8291
string? tagPrefix,

src/GitVersion.Core/MergeMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static bool TryParse(
100100
mergeMessage = null;
101101

102102
var mergedBranch = new MergeMessage(mergeCommit.Message, configuration).MergedBranch;
103-
var isReleaseBranch = mergedBranch != null && configuration.IsReleaseBranch(mergedBranch);
103+
var isReleaseBranch = mergedBranch is not null && configuration.IsReleaseBranch(mergedBranch);
104104
var isValidMergeCommit = mergeCommit.IsMergeCommit() || isReleaseBranch;
105105

106106
if (isValidMergeCommit)

src/GitVersion.Core/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static GitVersion.Git.BranchCommit.operator !=(GitVersion.Git.BranchCommit left,
769769
static GitVersion.Git.BranchCommit.operator ==(GitVersion.Git.BranchCommit left, GitVersion.Git.BranchCommit right) -> bool
770770
static GitVersion.Git.CommitExtensions.IsMergeCommit(this GitVersion.Git.ICommit! source) -> bool
771771
static GitVersion.Git.ReferenceName.FromBranchName(string! branchName) -> GitVersion.Git.ReferenceName!
772+
static GitVersion.Git.ReferenceName.operator !=(GitVersion.Git.ReferenceName? left, GitVersion.Git.ReferenceName? right) -> bool
773+
static GitVersion.Git.ReferenceName.operator ==(GitVersion.Git.ReferenceName? left, GitVersion.Git.ReferenceName? right) -> bool
772774
static GitVersion.Git.ReferenceName.Parse(string! canonicalName) -> GitVersion.Git.ReferenceName!
773775
static GitVersion.Git.ReferenceName.TryParse(out GitVersion.Git.ReferenceName? value, string! canonicalName) -> bool
774776
static GitVersion.Helpers.Disposable.Create(System.Action! disposer) -> System.IDisposable!

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ public void Enrich(TrunkBasedIteration iteration, TrunkBasedCommit commit, Trunk
1111
{
1212
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
1313
var incrementForcedByBranch = effectiveConfiguration.Increment.ToVersionField();
14-
var incrementForcedByCommit = GetIncrementForcedByCommit(context, commit.Value, effectiveConfiguration);
14+
var incrementForcedByCommit = commit.IsDummy
15+
? VersionField.None
16+
: GetIncrementForcedByCommit(context, commit.Value, effectiveConfiguration);
1517
commit.Increment = incrementForcedByCommit;
1618
context.Increment = context.Increment.Consolidate(incrementForcedByBranch, incrementForcedByCommit);
1719

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit co
2424
&& commit.GetEffectiveConfiguration(context.Configuration).IsReleaseBranch
2525
&& context.SemanticVersion is null
2626
&& (commit.Predecessor is null
27-
|| commit.Predecessor?.BranchName != commit.BranchName);
27+
|| commit.BranchName != commit.Predecessor?.BranchName);
2828

2929
public IEnumerable<IBaseVersionIncrement> GetIncrements(
3030
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace GitVersion.VersionCalculation.TrunkBased;
1010
"HasSuccessor = {" + nameof(HasSuccessor) + "}, HasPredecessor = {" + nameof(HasPredecessor) + "}, " +
1111
"HasChildIteration = {" + nameof(HasChildIteration) + "}, Message = {" + nameof(Message) + @"} \}"
1212
)]
13-
internal record TrunkBasedCommit(TrunkBasedIteration Iteration, ICommit Value, ReferenceName BranchName, IBranchConfiguration Configuration)
13+
internal record TrunkBasedCommit(TrunkBasedIteration Iteration, ICommit? value, ReferenceName BranchName, IBranchConfiguration Configuration)
1414
{
1515
public bool IsPredecessorTheLastCommitOnTrunk(IGitVersionConfiguration configuration)
1616
=> !GetEffectiveConfiguration(configuration).IsMainBranch && Predecessor?.GetEffectiveConfiguration(configuration).IsMainBranch == true;
@@ -31,9 +31,12 @@ public bool IsPredecessorTheLastCommitOnTrunk(IGitVersionConfiguration configura
3131

3232
public TrunkBasedCommit? Predecessor { get; private set; }
3333

34-
public ICommit Value { get; } = Value.NotNull();
34+
public ICommit Value => IsDummy ? (Successor?.Value)! : value!;
3535

36-
public string Message => Value.Message;
36+
[MemberNotNullWhen(false, nameof(Value))]
37+
public bool IsDummy => value is null;
38+
39+
public string Message => IsDummy ? "<<DUMMY>>" : Value.Message;
3740

3841
public TrunkBasedIteration? ChildIteration { get; private set; }
3942

@@ -101,7 +104,7 @@ public void AddSemanticVersions(IEnumerable<SemanticVersion> values)
101104
public void AddChildIteration(TrunkBasedIteration iteration) => ChildIteration = iteration.NotNull();
102105

103106
public TrunkBasedCommit Append(
104-
ICommit value, ReferenceName branchName, IBranchConfiguration configuration)
107+
ICommit? value, ReferenceName branchName, IBranchConfiguration configuration)
105108
{
106109
if (HasPredecessor) throw new InvalidOperationException();
107110

0 commit comments

Comments
 (0)