Skip to content

Commit 0bd90f5

Browse files
committed
Make code clean up and integrate code review suggestions.
1 parent c5512f2 commit 0bd90f5

File tree

8 files changed

+4
-115
lines changed

8 files changed

+4
-115
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace GitVersion.Core.Tests.VersionCalculation.Strategies;
88

99
[TestFixture]
10-
public class ConfiguredNextVersionBaseVersionStrategyTests : TestBase
10+
public class ConfiguredNextVersionVersionStrategyTests : TestBase
1111
{
1212
[Test]
1313
public void ReturnsNullWhenNoNextVersionIsInConfig()

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ public interface IRepositoryStore
1111

1212
ICommit? FindMergeBase(ICommit commit, ICommit mainlineTip);
1313
ICommit? GetCurrentCommit(IBranch currentBranch, string? commitId);
14-
IEnumerable<ICommit> GetMainlineCommitLog(ICommit? baseVersionSource, ICommit? mainlineTip);
15-
IEnumerable<ICommit> GetMergeBaseCommits(ICommit? mergeCommit, ICommit? mergedHead, ICommit? findMergeBase);
1614
IEnumerable<ICommit> GetCommitLog(ICommit? baseVersionSource, ICommit? currentCommit);
1715

1816
IBranch GetTargetBranch(string? targetBranchName);
1917
IBranch? FindBranch(ReferenceName branchName);
2018
IBranch? FindBranch(string branchName);
21-
IBranch? FindMainBranch(IGitVersionConfiguration configuration);
22-
IEnumerable<IBranch> FindMainlineBranches(IGitVersionConfiguration configuration);
2319
IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string, IBranchConfiguration>> releaseBranchConfig);
2420
IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude);
2521
IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false);
2622

27-
IDictionary<string, List<IBranch>> GetMainlineBranches(ICommit commit, IGitVersionConfiguration configuration);
28-
2923
/// <summary>
3024
/// Find the commit where the given branch was branched from another branch.
3125
/// If there are multiple such commits and branches, tries to guess based on commit histories.

src/GitVersion.Core/Core/BranchRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed class BranchRepository(Lazy<GitVersionContext> versionContext, I
1111

1212
private readonly IGitRepository gitRepository = gitRepository.NotNull();
1313

14-
public IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches)
14+
public IEnumerable<IBranch> GetMainBranches(params IBranch[] excludeBranches)
1515
=> GetBranches([.. excludeBranches], configuration => configuration.IsMainBranch == true);
1616

1717
public IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches)

src/GitVersion.Core/Core/IBranchRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace GitVersion.Core;
22

33
internal interface IBranchRepository
44
{
5-
IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches);
5+
IEnumerable<IBranch> GetMainBranches(params IBranch[] excludeBranches);
66

77
IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches);
88
}

src/GitVersion.Core/Core/RepositoryStore.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,6 @@ public RepositoryStore(ILog log, IGitRepository repository)
5555
return currentBranch.Tip;
5656
}
5757

58-
public IEnumerable<ICommit> GetMainlineCommitLog(ICommit? baseVersionSource, ICommit? mainlineTip)
59-
{
60-
if (mainlineTip is null)
61-
{
62-
return [];
63-
}
64-
65-
var filter = new CommitFilter { IncludeReachableFrom = mainlineTip, ExcludeReachableFrom = baseVersionSource, SortBy = CommitSortStrategies.Reverse, FirstParentOnly = true };
66-
67-
return this.repository.Commits.QueryBy(filter);
68-
}
69-
70-
public IEnumerable<ICommit> GetMergeBaseCommits(ICommit? mergeCommit, ICommit? mergedHead, ICommit? findMergeBase)
71-
{
72-
var filter = new CommitFilter { IncludeReachableFrom = mergedHead, ExcludeReachableFrom = findMergeBase };
73-
var commitCollection = this.repository.Commits.QueryBy(filter);
74-
75-
var commits = mergeCommit != null
76-
? new[] { mergeCommit }.Union(commitCollection)
77-
: commitCollection;
78-
return commits;
79-
}
80-
8158
public IBranch GetTargetBranch(string? targetBranchName)
8259
{
8360
// By default, we assume HEAD is pointing to the desired branch
@@ -108,35 +85,6 @@ public IBranch GetTargetBranch(string? targetBranchName)
10885

10986
public IBranch? FindBranch(string branchName) => this.repository.Branches.FirstOrDefault(x => x.Name.EquivalentTo(branchName));
11087

111-
public IBranch? FindMainBranch(IGitVersionConfiguration configuration)
112-
{
113-
var branches = configuration.Branches;
114-
var mainBranchRegex = branches[ConfigurationConstants.MainBranchKey].RegularExpression
115-
?? branches[ConfigurationConstants.MasterBranchKey].RegularExpression;
116-
117-
if (mainBranchRegex == null)
118-
{
119-
return FindBranch(ConfigurationConstants.MainBranchKey) ?? FindBranch(ConfigurationConstants.MasterBranchKey);
120-
}
121-
122-
return this.repository.Branches.FirstOrDefault(b =>
123-
Regex.IsMatch(b.Name.WithoutOrigin, mainBranchRegex, RegexOptions.IgnoreCase));
124-
}
125-
126-
public IEnumerable<IBranch> FindMainlineBranches(IGitVersionConfiguration configuration)
127-
{
128-
configuration.NotNull();
129-
130-
foreach (var branch in this.repository.Branches)
131-
{
132-
var branchConfiguration = configuration.GetBranchConfiguration(branch.Name);
133-
if (branchConfiguration.IsMainBranch == true)
134-
{
135-
yield return branch;
136-
}
137-
}
138-
}
139-
14088
public IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string, IBranchConfiguration>> releaseBranchConfig)
14189
=> this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig));
14290

@@ -153,12 +101,6 @@ public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumera
153101
return branchesContainingCommitFinder.GetBranchesContainingCommit(commit, branches, onlyTrackedBranches);
154102
}
155103

156-
public IDictionary<string, List<IBranch>> GetMainlineBranches(ICommit commit, IGitVersionConfiguration configuration)
157-
{
158-
var mainlineBranchFinder = new MainlineBranchFinder(this, this.repository, configuration, this.log);
159-
return mainlineBranchFinder.FindMainlineBranches(commit);
160-
}
161-
162104
public IEnumerable<IBranch> GetSourceBranches(IBranch branch, IGitVersionConfiguration configuration,
163105
params IBranch[] excludedBranches)
164106
=> GetSourceBranches(branch, configuration, (IEnumerable<IBranch>)excludedBranches);

src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
199199
using (this.log.IndentLog($"Getting tagged semantic versions of mainline branches. " +
200200
$"TagPrefix: {tagPrefix} and Format: {format}"))
201201
{
202-
foreach (var mainlinemBranch in branchRepository.GetMainlineBranches(excludeBranches))
202+
foreach (var mainlinemBranch in branchRepository.GetMainBranches(excludeBranches))
203203
{
204204
foreach (var semanticVersion in GetTaggedSemanticVersionsOfBranch(mainlinemBranch, tagPrefix, format).SelectMany(_ => _))
205205
{

src/GitVersion.Core/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,12 @@ GitVersion.Common.IRepositoryStore.FindBranch(string! branchName) -> GitVersion.
9393
GitVersion.Common.IRepositoryStore.FindCommitBranchWasBranchedFrom(GitVersion.IBranch? branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, params GitVersion.IBranch![]! excludedBranches) -> GitVersion.BranchCommit
9494
GitVersion.Common.IRepositoryStore.FindCommitBranchesWasBranchedFrom(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, System.Collections.Generic.IEnumerable<GitVersion.IBranch!>! excludedBranches) -> System.Collections.Generic.IEnumerable<GitVersion.BranchCommit>!
9595
GitVersion.Common.IRepositoryStore.FindCommitBranchesWasBranchedFrom(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, params GitVersion.IBranch![]! excludedBranches) -> System.Collections.Generic.IEnumerable<GitVersion.BranchCommit>!
96-
GitVersion.Common.IRepositoryStore.FindMainBranch(GitVersion.Configuration.IGitVersionConfiguration! configuration) -> GitVersion.IBranch?
97-
GitVersion.Common.IRepositoryStore.FindMainlineBranches(GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable<GitVersion.IBranch!>!
9896
GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.IBranch? branch, GitVersion.IBranch? otherBranch) -> GitVersion.ICommit?
9997
GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.ICommit! commit, GitVersion.ICommit! mainlineTip) -> GitVersion.ICommit?
10098
GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.ICommit! commit, System.Collections.Generic.IEnumerable<GitVersion.IBranch!>? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable<GitVersion.IBranch!>!
10199
GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.ICommit? baseVersionSource, GitVersion.ICommit? currentCommit) -> System.Collections.Generic.IEnumerable<GitVersion.ICommit!>!
102100
GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.IBranch! currentBranch, string? commitId) -> GitVersion.ICommit?
103101
GitVersion.Common.IRepositoryStore.GetCurrentCommitTaggedVersion(GitVersion.ICommit? commit, string? tagPrefix, GitVersion.SemanticVersionFormat format, bool handleDetachedBranch) -> GitVersion.SemanticVersion?
104-
GitVersion.Common.IRepositoryStore.GetMainlineBranches(GitVersion.ICommit! commit, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IDictionary<string!, System.Collections.Generic.List<GitVersion.IBranch!>!>!
105-
GitVersion.Common.IRepositoryStore.GetMainlineCommitLog(GitVersion.ICommit? baseVersionSource, GitVersion.ICommit? mainlineTip) -> System.Collections.Generic.IEnumerable<GitVersion.ICommit!>!
106-
GitVersion.Common.IRepositoryStore.GetMergeBaseCommits(GitVersion.ICommit? mergeCommit, GitVersion.ICommit? mergedHead, GitVersion.ICommit? findMergeBase) -> System.Collections.Generic.IEnumerable<GitVersion.ICommit!>!
107102
GitVersion.Common.IRepositoryStore.GetNumberOfUncommittedChanges() -> int
108103
GitVersion.Common.IRepositoryStore.GetReleaseBranches(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, GitVersion.Configuration.IBranchConfiguration!>>! releaseBranchConfig) -> System.Collections.Generic.IEnumerable<GitVersion.IBranch!>!
109104
GitVersion.Common.IRepositoryStore.GetSourceBranches(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, System.Collections.Generic.IEnumerable<GitVersion.IBranch!>! excludedBranches) -> System.Collections.Generic.IEnumerable<GitVersion.IBranch!>!

src/GitVersion.Core/VersionCalculation/VariableProvider.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,6 @@ public GitVersionVariables GetVariablesFor(
7979
);
8080
}
8181

82-
private static SemanticVersion PromoteNumberOfCommitsToTagNumber(SemanticVersion semanticVersion, string preReleaseTagName)
83-
{
84-
var preReleaseTagNumber = semanticVersion.PreReleaseTag.Number;
85-
long buildMetaDataCommitsSinceVersionSource;
86-
var buildMetaDataCommitsSinceTag = semanticVersion.BuildMetaData.CommitsSinceTag;
87-
88-
// For continuous deployment the commits since tag gets promoted to the pre-release number
89-
if (!semanticVersion.BuildMetaData.CommitsSinceTag.HasValue)
90-
{
91-
preReleaseTagNumber = null;
92-
buildMetaDataCommitsSinceVersionSource = 0;
93-
}
94-
else
95-
{
96-
// Number of commits since last tag should be added to PreRelease number if given. Remember to deduct automatic version bump.
97-
if (preReleaseTagNumber.HasValue)
98-
{
99-
preReleaseTagNumber += semanticVersion.BuildMetaData.CommitsSinceTag - 1;
100-
}
101-
else
102-
{
103-
preReleaseTagNumber = semanticVersion.BuildMetaData.CommitsSinceTag;
104-
}
105-
buildMetaDataCommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value;
106-
buildMetaDataCommitsSinceTag = null; // why is this set to null ?
107-
}
108-
109-
return new(semanticVersion)
110-
{
111-
PreReleaseTag = new(semanticVersion.PreReleaseTag)
112-
{
113-
Name = preReleaseTagName,
114-
Number = preReleaseTagNumber
115-
},
116-
BuildMetaData = new(semanticVersion.BuildMetaData)
117-
{
118-
CommitsSinceVersionSource = buildMetaDataCommitsSinceVersionSource,
119-
CommitsSinceTag = buildMetaDataCommitsSinceTag
120-
}
121-
};
122-
}
123-
12482
private string? CheckAndFormatString<T>(string? formatString, T source, string? defaultValue, string formatVarName)
12583
{
12684
string? formattedString;

0 commit comments

Comments
 (0)