File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
VersionCalculation/BaseVersionCalculators Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public interface IRepositoryStore
1818
1919 IBranch GetTargetBranch ( string ? targetBranchName ) ;
2020 IBranch ? FindBranch ( string ? branchName ) ;
21+ IBranch ? FindMainBranch ( Config configuration ) ;
2122 IBranch ? GetChosenBranch ( Config configuration ) ;
2223 IEnumerable < IBranch > GetBranchesForCommit ( ICommit commit ) ;
2324 IEnumerable < IBranch > GetExcludedInheritBranches ( Config configuration ) ;
Original file line number Diff line number Diff line change @@ -126,6 +126,18 @@ public IBranch GetTargetBranch(string? targetBranchName)
126126
127127 public IBranch ? FindBranch ( string ? branchName ) => this . repository . Branches . FirstOrDefault ( x => x . Name . EquivalentTo ( branchName ) ) ;
128128
129+ public IBranch ? FindMainBranch ( Config configuration )
130+ {
131+ var mainBranchRegex = configuration . Branches [ Config . MainBranchKey ] ? . Regex ;
132+ if ( mainBranchRegex == null )
133+ {
134+ return null ;
135+ }
136+
137+ return this . repository . Branches . FirstOrDefault ( b =>
138+ Regex . IsMatch ( b . Name . Friendly , mainBranchRegex , RegexOptions . IgnoreCase ) ) ;
139+ }
140+
129141 public IBranch ? GetChosenBranch ( Config configuration )
130142 {
131143 var developBranchRegex = configuration . Branches [ Config . DevelopBranchKey ] ? . Regex ;
Original file line number Diff line number Diff line change @@ -26,14 +26,16 @@ public class TrackReleaseBranchesVersionStrategy : VersionStrategyBase
2626 private readonly IRepositoryStore repositoryStore ;
2727 private readonly VersionInBranchNameVersionStrategy releaseVersionStrategy ;
2828 private readonly TaggedCommitVersionStrategy taggedCommitVersionStrategy ;
29+ private readonly Config configuration ;
30+
2931
3032 public TrackReleaseBranchesVersionStrategy ( IRepositoryStore repositoryStore , Lazy < GitVersionContext > versionContext )
3133 : base ( versionContext )
3234 {
3335 this . repositoryStore = repositoryStore . NotNull ( ) ;
34-
3536 this . releaseVersionStrategy = new VersionInBranchNameVersionStrategy ( repositoryStore , versionContext ) ;
3637 this . taggedCommitVersionStrategy = new TaggedCommitVersionStrategy ( repositoryStore , versionContext ) ;
38+ this . configuration = versionContext . Value . Configuration . Configuration ;
3739 }
3840
3941 public override IEnumerable < BaseVersion > GetVersions ( ) =>
@@ -43,9 +45,7 @@ public override IEnumerable<BaseVersion> GetVersions() =>
4345
4446 private IEnumerable < BaseVersion > MainTagsVersions ( )
4547 {
46- var main = this . repositoryStore . FindBranch ( Config . MainBranchKey )
47- // For compatibility reason try to find `master` if `main` cannot be found
48- ?? this . repositoryStore . FindBranch ( Config . MasterBranchKey ) ;
48+ var main = this . repositoryStore . FindMainBranch ( this . configuration ) ;
4949
5050 return main != null
5151 ? this . taggedCommitVersionStrategy . GetTaggedVersions ( main , null )
You can’t perform that action at this time.
0 commit comments