Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e2dc05c
Create TrunkBasedVersionStrategy implementation (see https://github.c…
HHobeck Nov 25, 2023
4a74198
Cretae TrunkBasedVersionStrategy implementation (see https://github.c…
HHobeck Nov 26, 2023
6464608
Fix Code Format warning
HHobeck Nov 26, 2023
7127113
Code format error CHARSET: Fix file encoding.
HHobeck Nov 26, 2023
3c2fd42
dotnet format ./src/ --exclude **/AddFormats/
HHobeck Nov 26, 2023
31e2c85
Remove TrunkBasedVersionCalculator and fix IsMatchForBranchSpecificLabel
HHobeck Nov 26, 2023
8f8d721
Fix unit tests
HHobeck Nov 26, 2023
515ab57
Create integration tests for TrunkBasedVersionStrategy
HHobeck Nov 27, 2023
0ebc6fb
Support of TrackMergeTarget for the TrunkBased branching strategy.
HHobeck Nov 30, 2023
979df23
cleanup
arturcic Dec 1, 2023
94fdd4f
Move CreateNextVersion back to NextVersionCalculator
HHobeck Dec 1, 2023
a6fb134
Add integration test where a develop branch with one commit merged to…
HHobeck Dec 1, 2023
995d8d8
Cretae integration tests when a feature branch with one commit has be…
HHobeck Dec 2, 2023
d241d0a
Given a feature branch with one commit branched from main when commit…
HHobeck Dec 2, 2023
d3e05d4
Given a feature branch with one commit branched from main when commit…
HHobeck Dec 3, 2023
bd3aca3
Given a feature branch with one commit merged to main when commit B t…
HHobeck Dec 3, 2023
1b9030f
Given a feature branch with one commit branched from main when commit…
HHobeck Dec 3, 2023
563e4ca
Given a feature branch with a merge commit from main merged back to m…
HHobeck Dec 5, 2023
ee3ff3b
Given a main branch with one commit when commit has bump message Patc…
HHobeck Dec 5, 2023
87ad779
Given a main branch with one commit when commit tagged as pre-release…
HHobeck Dec 5, 2023
6b98692
Given a main branch with one commit branched to feature
HHobeck Dec 6, 2023
0a1671f
Given a main branch with one commit branched to feature when commit h…
HHobeck Dec 7, 2023
78ea65c
Given a develop branch with one commit merged to main when merged com…
HHobeck Dec 7, 2023
5261f77
Given a main branch with one commit branched to feature when commit t…
HHobeck Dec 8, 2023
df907ef
Given a main branch with one commit branched to feature when commit t…
HHobeck Dec 8, 2023
d1bd8db
Add entries to the PublicAPI.Unshipped.txt file
HHobeck Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void GetBranchesContainingCommitThrowsDirectlyOnNullCommit()
var fixtureRepository = fixture.Repository.ToGitRepository();
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);

Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null));
Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null!));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public void CanTakeVersionFromHotfixesBranch()
r.MakeATaggedCommit("2.0.0");
});
// Merge hotfix branch to support
Commands.Checkout(fixture.Repository, MainBranch);
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("support-1.1", (LibGit2Sharp.Commit)fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target));
var branch = fixture.Repository.CreateBranch(
"support-1.1", (LibGit2Sharp.Commit)fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target
);
Commands.Checkout(fixture.Repository, branch);
fixture.AssertFullSemver("1.1.0");

// create hotfix branch
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfixes/1.1.1"));
fixture.AssertFullSemver("1.1.1+0");
fixture.AssertFullSemver("1.1.1-beta.1+0");
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("1.1.1-beta.1+1");
Expand All @@ -85,7 +87,7 @@ public void PatchOlderReleaseExample()

// create hotfix branch
fixture.BranchTo("hotfix-1.1.1");
fixture.AssertFullSemver("1.1.1+0");
fixture.AssertFullSemver("1.1.1-beta.1+0");
fixture.MakeACommit();

fixture.AssertFullSemver("1.1.1-beta.1+1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public void RepositoryWithALotOfTags()
var sw = Stopwatch.StartNew();

fixture.AssertFullSemver($"1.0.{maxCommits}-feature.1+1", configuration);
sw.Stop();

sw.ElapsedMilliseconds.ShouldBeLessThan(5000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void WhenSupportIsBranchedFromMainWithSpecificTag()
using var fixture = new EmptyRepositoryFixture();

fixture.MakeACommit();
fixture.AssertFullSemver("0.0.1-1");
fixture.AssertFullSemver("0.0.1-1", configuration);

fixture.ApplyTag("1.4.0-rc");
fixture.MakeACommit();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests;
using GitVersion.Core.Tests.IntegrationTests;
using GitVersion.VersionCalculation;

namespace GitVersion.Core.TrunkBased;

internal partial class TrunkBasedScenariosWithAGitFlow
{
[Parallelizable(ParallelScope.All)]
public class GivenADevelopBranchWithOneCommitMergedToMainWhen
{
private EmptyRepositoryFixture? fixture;

private static GitFlowConfigurationBuilder TrunkBasedBuilder => GitFlowConfigurationBuilder.New.WithLabel(null)
.WithVersioningMode(VersioningMode.TrunkBased)
.WithBranch("main", _ => _.WithVersioningMode(VersioningMode.ManualDeployment))
.WithBranch("develop", _ => _.WithVersioningMode(VersioningMode.ManualDeployment));

[OneTimeSetUp]
public void OneTimeSetUp()
{
// * 55 minutes ago (HEAD -> main)
// |\
// | * 56 minutes ago (develop)
// |/
// * 58 minutes ago

fixture = new EmptyRepositoryFixture("main");

fixture.MakeACommit("A");
fixture.BranchTo("develop");
fixture.MakeACommit("B");
fixture.MergeTo("main");
}

[OneTimeTearDown]
public void OneTimeTearDown() => fixture?.Dispose();

[TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "0.0.2-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "0.1.1-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "0.2.0-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+2")]
public string GetVersionWithNoLabelOnMain(IncrementStrategy incrementOnMain, IncrementStrategy increment)
{
IGitVersionConfiguration trunkBased = TrunkBasedBuilder
.WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(null))
.WithBranch("develop", _ => _.WithIncrement(increment))
.Build();

return fixture!.GetVersion(trunkBased).FullSemVer;
}

[TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "0.0.0-2+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "0.0.1-1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "0.1.0-1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "1.0.0-1+2")]

[TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "0.0.1-2+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "0.0.2-1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "0.1.0-1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "1.0.0-1+2")]

[TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "0.1.0-2+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "0.1.1-1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "0.2.0-1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "1.0.0-1+2")]

[TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "1.0.0-2+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "1.0.1-1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "1.1.0-1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-1+2")]
public string GetVersionWithEmptyLabelOnMain(IncrementStrategy incrementOnMain, IncrementStrategy increment)
{
IGitVersionConfiguration trunkBased = TrunkBasedBuilder
.WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(string.Empty))
.WithBranch("develop", _ => _.WithIncrement(increment))
.Build();

return fixture!.GetVersion(trunkBased).FullSemVer;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests;
using GitVersion.Core.Tests.IntegrationTests;
using GitVersion.VersionCalculation;

namespace GitVersion.Core.TrunkBased;

internal partial class TrunkBasedScenariosWithAGitFlow
{
[Parallelizable(ParallelScope.All)]
public class GivenADevelopBranchWithOneCommitMergedToMainWhenMergedCommitTaggedAsStable
{
private EmptyRepositoryFixture? fixture;

private static GitFlowConfigurationBuilder TrunkBasedBuilder => GitFlowConfigurationBuilder.New.WithLabel(null)
.WithVersioningMode(VersioningMode.TrunkBased)
.WithBranch("main", _ => _.WithVersioningMode(VersioningMode.ManualDeployment))
.WithBranch("develop", _ => _.WithVersioningMode(VersioningMode.ManualDeployment));

[OneTimeSetUp]
public void OneTimeSetUp()
{
// * 55 minutes ago (tag: 1.0.0, main)
// |\
// | * 56 minutes ago (HEAD -> develop)
// |/
// * 58 minutes ago

fixture = new EmptyRepositoryFixture("main");

fixture.MakeACommit("A");
fixture.BranchTo("develop");
fixture.MakeACommit("B");
fixture.MergeTo("main");
fixture.ApplyTag("1.0.0");
fixture.Checkout("develop");
}

[OneTimeTearDown]
public void OneTimeTearDown() => fixture?.Dispose();

[TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")]

[TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")]

[TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")]

[TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")]
public string GetVersionWithTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment)
{
IGitVersionConfiguration trunkBased = TrunkBasedBuilder
.WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(null))
.WithBranch("develop", _ => _.WithIncrement(increment).WithTrackMergeTarget(true))
.Build();

return fixture!.GetVersion(trunkBased).FullSemVer;
}

[TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]

[TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")]
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")]
public string GetVersionWithNoTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment)
{
IGitVersionConfiguration trunkBased = TrunkBasedBuilder
.WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(null))
.WithBranch("develop", _ => _.WithIncrement(increment).WithTrackMergeTarget(false))
.Build();

return fixture!.GetVersion(trunkBased).FullSemVer;
}
}
}
Loading