Skip to content

Commit eea7c9b

Browse files
authored
Merge pull request #3844 from HHobeck/feature/Replace-the-version-mode-Mainline-Part-I.A
Feature/replace the version mode mainline part i.a
2 parents 5e71ec2 + dcadb4a commit eea7c9b

File tree

47 files changed

+2215
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2215
-191
lines changed

src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void GetBranchesContainingCommitThrowsDirectlyOnNullCommit()
209209
var fixtureRepository = fixture.Repository.ToGitRepository();
210210
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);
211211

212-
Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null));
212+
Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null!));
213213
}
214214

215215
[Test]

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ public void CanTakeVersionFromHotfixesBranch()
5353
r.MakeATaggedCommit("2.0.0");
5454
});
5555
// Merge hotfix branch to support
56-
Commands.Checkout(fixture.Repository, MainBranch);
57-
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("support-1.1", (LibGit2Sharp.Commit)fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target));
56+
var branch = fixture.Repository.CreateBranch(
57+
"support-1.1", (LibGit2Sharp.Commit)fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target
58+
);
59+
Commands.Checkout(fixture.Repository, branch);
5860
fixture.AssertFullSemver("1.1.0");
5961

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

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

8688
// create hotfix branch
8789
fixture.BranchTo("hotfix-1.1.1");
88-
fixture.AssertFullSemver("1.1.1+0");
90+
fixture.AssertFullSemver("1.1.1-beta.1+0");
8991
fixture.MakeACommit();
9092

9193
fixture.AssertFullSemver("1.1.1-beta.1+1");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public void RepositoryWithALotOfTags()
2424
var sw = Stopwatch.StartNew();
2525

2626
fixture.AssertFullSemver($"1.0.{maxCommits}-feature.1+1", configuration);
27+
sw.Stop();
28+
2729
sw.ElapsedMilliseconds.ShouldBeLessThan(5000);
2830
}
2931
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void WhenSupportIsBranchedFromMainWithSpecificTag()
7979
using var fixture = new EmptyRepositoryFixture();
8080

8181
fixture.MakeACommit();
82-
fixture.AssertFullSemver("0.0.1-1");
82+
fixture.AssertFullSemver("0.0.1-1", configuration);
8383

8484
fixture.ApplyTag("1.4.0-rc");
8585
fixture.MakeACommit();

src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs

Lines changed: 1380 additions & 0 deletions
Large diffs are not rendered by default.

src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ConfigNextVersionTest(string nextVersion, string expectedVersion, Se
3333

3434
baseVersion.ShouldNotBeNull();
3535
baseVersion.ShouldIncrement.ShouldBe(false);
36-
baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
36+
baseVersion.GetSemanticVersion().ToString().ShouldBe(expectedVersion);
3737
}
3838

3939
[TestCase("0.1", SemanticVersionFormat.Strict)]

src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private static void AssertMergeMessage(string message, string? expectedVersion,
177177
else
178178
{
179179
baseVersion.ShouldNotBeNull();
180-
baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
180+
baseVersion.GetSemanticVersion().ToString().ShouldBe(expectedVersion);
181181
}
182182
}
183183

src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expe
2828
strategy.ShouldNotBeNull();
2929
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
3030

31-
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
31+
baseVersion.GetSemanticVersion().ToString().ShouldBe(expectedBaseVersion);
3232
}
3333

3434
[TestCase("origin/hotfix-2.0.0")]
@@ -90,7 +90,7 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
9090
strategy.ShouldNotBeNull();
9191
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
9292

93-
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
93+
baseVersion.GetSemanticVersion().ToString().ShouldBe(expectedBaseVersion);
9494
}
9595

9696
[TestCase("origin", "release-2.0.0", "2.0.0")]
@@ -114,7 +114,7 @@ public void CanTakeVersionFromNameOfRemoteReleaseBranch(string origin, string br
114114
strategy.ShouldNotBeNull();
115115
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
116116

117-
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
117+
baseVersion.GetSemanticVersion().ToString().ShouldBe(expectedBaseVersion);
118118
}
119119

120120
private static IVersionStrategy GetVersionStrategy(IGitRepository repository,

src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ public interface IRepositoryStore
1616
IEnumerable<ICommit> GetCommitLog(ICommit? baseVersionSource, ICommit? currentCommit);
1717

1818
IBranch GetTargetBranch(string? targetBranchName);
19-
IBranch? FindBranch(string? branchName);
19+
IBranch? FindBranch(ReferenceName branchName);
20+
IBranch? FindBranch(string branchName);
2021
IBranch? FindMainBranch(IGitVersionConfiguration configuration);
2122
IEnumerable<IBranch> FindMainlineBranches(IGitVersionConfiguration configuration);
2223
IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string, IBranchConfiguration>> releaseBranchConfig);
2324
IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude);
24-
IEnumerable<IBranch> GetBranchesContainingCommit(ICommit? commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false);
25+
IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false);
2526

2627
IDictionary<string, List<IBranch>> GetMainlineBranches(ICommit commit, IGitVersionConfiguration configuration);
2728

@@ -41,8 +42,6 @@ public interface IRepositoryStore
4142

4243
SemanticVersion? GetCurrentCommitTaggedVersion(ICommit? commit, string? tagPrefix, SemanticVersionFormat format, bool handleDetachedBranch);
4344

44-
IEnumerable<SemanticVersion> GetVersionTagsOnBranch(IBranch branch, string? tagPrefix, SemanticVersionFormat format);
45-
4645
IReadOnlyList<SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format);
4746

4847
IReadOnlyList<SemanticVersionWithTag> GetTaggedSemanticVersionsOnBranch(IBranch branch, string? tagPrefix, SemanticVersionFormat format);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using GitVersion.Configuration;
2+
using GitVersion.Extensions;
3+
4+
namespace GitVersion.Core;
5+
6+
internal sealed class BranchRepository : IBranchRepository
7+
{
8+
private GitVersionContext VersionContext => this.versionContextLazy.Value;
9+
private readonly Lazy<GitVersionContext> versionContextLazy;
10+
11+
private readonly IGitRepository gitRepository;
12+
13+
public BranchRepository(Lazy<GitVersionContext> versionContext, IGitRepository gitRepository)
14+
{
15+
this.versionContextLazy = versionContext.NotNull();
16+
this.gitRepository = gitRepository.NotNull();
17+
}
18+
19+
public IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches)
20+
=> GetBranches(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsMainline == true);
21+
22+
public IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches)
23+
=> GetBranches(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsReleaseBranch == true);
24+
25+
private IEnumerable<IBranch> GetBranches(HashSet<IBranch> excludeBranches, Func<IBranchConfiguration, bool> predicate)
26+
{
27+
predicate.NotNull();
28+
29+
foreach (var branch in this.gitRepository.Branches)
30+
{
31+
if (!excludeBranches.Contains(branch))
32+
{
33+
var branchConfiguration = VersionContext.Configuration.GetBranchConfiguration(branch.Name);
34+
if (predicate(branchConfiguration))
35+
{
36+
yield return branch;
37+
}
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)