@@ -49,31 +49,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
49
49
var parentCount = currentCommit . Parents . Count ( ) ;
50
50
if ( parentCount == 2 )
51
51
{
52
- var parents = currentCommit . Parents . ToArray ( ) ;
53
- var branch = repository . Branches . SingleOrDefault ( b => ! b . IsRemote && b . Tip == parents [ 1 ] ) ;
54
- if ( branch != null )
55
- {
56
- excludedBranches = new [ ]
57
- {
58
- currentBranch ,
59
- branch
60
- } ;
61
- currentBranch = branch ;
62
- }
63
- else
64
- {
65
- var possibleTargetBranches = repository . Branches . Where ( b => ! b . IsRemote && b . Tip == parents [ 0 ] ) . ToList ( ) ;
66
- if ( possibleTargetBranches . Count ( ) > 1 )
67
- {
68
- currentBranch = possibleTargetBranches . FirstOrDefault ( b => b . Name == "master" ) ?? possibleTargetBranches . First ( ) ;
69
- }
70
- else
71
- {
72
- currentBranch = possibleTargetBranches . FirstOrDefault ( ) ?? currentBranch ;
73
- }
74
- }
75
-
76
- Logger . WriteInfo ( "HEAD is merge commit, this is likely a pull request using " + currentBranch . Name + " as base" ) ;
52
+ excludedBranches = CalculateWhenMultipleParents ( repository , currentCommit , ref currentBranch , excludedBranches ) ;
77
53
}
78
54
if ( excludedInheritBranches == null )
79
55
{
@@ -142,5 +118,41 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
142
118
} ) ;
143
119
}
144
120
}
121
+
122
+ static Branch [ ] CalculateWhenMultipleParents ( IRepository repository , Commit currentCommit , ref Branch currentBranch , Branch [ ] excludedBranches )
123
+ {
124
+ var parents = currentCommit . Parents . ToArray ( ) ;
125
+ var branches = repository . Branches . Where ( b => ! b . IsRemote && b . Tip == parents [ 1 ] ) . ToList ( ) ;
126
+ if ( branches . Count == 1 )
127
+ {
128
+ var branch = branches [ 0 ] ;
129
+ excludedBranches = new [ ]
130
+ {
131
+ currentBranch ,
132
+ branch
133
+ } ;
134
+ currentBranch = branch ;
135
+ }
136
+ else if ( branches . Count > 1 )
137
+ {
138
+ currentBranch = branches . FirstOrDefault ( b => b . Name == "master" ) ?? branches . First ( ) ;
139
+ }
140
+ else
141
+ {
142
+ var possibleTargetBranches = repository . Branches . Where ( b => ! b . IsRemote && b . Tip == parents [ 0 ] ) . ToList ( ) ;
143
+ if ( possibleTargetBranches . Count > 1 )
144
+ {
145
+ currentBranch = possibleTargetBranches . FirstOrDefault ( b => b . Name == "master" ) ?? possibleTargetBranches . First ( ) ;
146
+ }
147
+ else
148
+ {
149
+ currentBranch = possibleTargetBranches . FirstOrDefault ( ) ?? currentBranch ;
150
+ }
151
+ }
152
+
153
+ Logger . WriteInfo ( "HEAD is merge commit, this is likely a pull request using " + currentBranch . Name + " as base" ) ;
154
+
155
+ return excludedBranches ;
156
+ }
145
157
}
146
158
}
0 commit comments