@@ -4,6 +4,9 @@ namespace GitVersion
4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
6
using System . Text . RegularExpressions ;
7
+
8
+ using JetBrains . Annotations ;
9
+
7
10
using LibGit2Sharp ;
8
11
9
12
public class BranchConfigurationCalculator
@@ -35,11 +38,22 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
35
38
throw new Exception ( string . Format ( format , currentBranch . Name , string . Join ( ", " , matchingBranches . Select ( b => b . Key ) ) ) ) ;
36
39
}
37
40
38
- static KeyValuePair < string , BranchConfig > [ ] LookupBranchConfiguration ( Config config , Branch currentBranch )
41
+ static KeyValuePair < string , BranchConfig > [ ] LookupBranchConfiguration ( [ NotNull ] Config config , [ NotNull ] Branch currentBranch )
39
42
{
43
+ if ( config == null )
44
+ {
45
+ throw new ArgumentNullException ( "config" ) ;
46
+ }
47
+
48
+ if ( currentBranch == null )
49
+ {
50
+ throw new ArgumentNullException ( "currentBranch" ) ;
51
+ }
52
+
40
53
return config . Branches . Where ( b => Regex . IsMatch ( currentBranch . Name , "^" + b . Key , RegexOptions . IgnoreCase ) ) . ToArray ( ) ;
41
54
}
42
55
56
+
43
57
static KeyValuePair < string , BranchConfig > InheritBranchConfiguration ( bool onlyEvaluateTrackedBranches , IRepository repository , Commit currentCommit , Branch currentBranch , KeyValuePair < string , BranchConfig > keyValuePair , BranchConfig branchConfiguration , Config config , IList < Branch > excludedInheritBranches )
44
58
{
45
59
using ( Logger . IndentLog ( "Attempting to inherit branch configuration from parent branch" ) )
@@ -104,11 +118,15 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
104
118
else
105
119
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string . Join ( ", " , possibleParents . Select ( p => p . Name ) ) ;
106
120
107
- var developBranch = repository . Branches . FirstOrDefault ( b => Regex . IsMatch ( b . Name , "^develop" , RegexOptions . IgnoreCase ) ) ;
108
- var branchName = developBranch != null ? developBranch . Name : "master" ;
121
+ var chosenBranch = repository . Branches . FirstOrDefault ( b => Regex . IsMatch ( b . Name , "^develop" , RegexOptions . IgnoreCase )
122
+ || Regex . IsMatch ( b . Name , "master$" , RegexOptions . IgnoreCase ) ) ;
123
+ if ( chosenBranch == null )
124
+ throw new InvalidOperationException ( "Could not find a 'develop' or 'master' branch, neither locally nor remotely." ) ;
109
125
126
+ var branchName = chosenBranch . Name ;
110
127
Logger . WriteWarning ( errorMessage + Environment . NewLine + Environment . NewLine + "Falling back to " + branchName + " branch config" ) ;
111
- var value = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , repository . Branches [ branchName ] ) . Value ;
128
+
129
+ var value = GetBranchConfiguration ( currentCommit , repository , onlyEvaluateTrackedBranches , config , chosenBranch ) . Value ;
112
130
return new KeyValuePair < string , BranchConfig > (
113
131
keyValuePair . Key ,
114
132
new BranchConfig ( branchConfiguration )
0 commit comments