@@ -106,14 +106,47 @@ public IEnumerable<IBranch> GetSourceBranches(IBranch branch, IGitVersionConfigu
106
106
params IBranch [ ] excludedBranches )
107
107
=> GetSourceBranches ( branch , configuration , ( IEnumerable < IBranch > ) excludedBranches ) ;
108
108
109
- public IEnumerable < IBranch > GetSourceBranches ( IBranch branch , IGitVersionConfiguration configuration , IEnumerable < IBranch > excludedBranches )
109
+ public IEnumerable < IBranch > GetSourceBranches (
110
+ IBranch branch , IGitVersionConfiguration configuration , IEnumerable < IBranch > excludedBranches )
110
111
{
111
112
var returnedBranches = new HashSet < IBranch > ( ) ;
112
113
113
114
var referenceLookup = this . repository . Refs . ToLookup ( r => r . TargetIdentifier ) ;
114
115
115
- foreach ( var branchGrouping in FindCommitBranchesWasBranchedFrom ( branch , configuration , excludedBranches )
116
- . GroupBy ( element => element . Commit , element => element . Branch ) )
116
+ var commitBranches = FindCommitBranchesWasBranchedFrom ( branch , configuration , excludedBranches ) . ToHashSet ( ) ;
117
+
118
+ var ignore = new HashSet < BranchCommit > ( ) ;
119
+ foreach ( var commitBranch in commitBranches )
120
+ {
121
+ foreach ( var commit in branch . Commits . Where ( element => element . When > commitBranch . Commit . When ) )
122
+ {
123
+ var parents = commit . Parents . ToArray ( ) ;
124
+ if ( parents . Length > 1 && parents . Any ( element => element . Equals ( commitBranch . Commit ) ) )
125
+ {
126
+ ignore . Add ( commitBranch ) ;
127
+ }
128
+ }
129
+ }
130
+
131
+ foreach ( var item in commitBranches . Skip ( 1 ) . Reverse ( ) )
132
+ {
133
+ if ( ignore . Contains ( item ) ) continue ;
134
+
135
+ foreach ( var commitBranche in commitBranches )
136
+ {
137
+ if ( item . Commit . Equals ( commitBranche . Commit ) ) break ;
138
+
139
+ foreach ( var commit in commitBranche . Branch . Commits . Where ( element => element . When >= item . Commit . When ) )
140
+ {
141
+ if ( commit . Equals ( item . Commit ) )
142
+ {
143
+ commitBranches . Remove ( item ) ;
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ foreach ( var branchGrouping in commitBranches . GroupBy ( element => element . Commit , element => element . Branch ) )
117
150
{
118
151
bool referenceMatchFound = false ;
119
152
var referenceNames = referenceLookup [ branchGrouping . Key . Sha ] . Select ( element => element . Name ) . ToHashSet ( ) ;
@@ -180,18 +213,10 @@ public IEnumerable<BranchCommit> FindCommitBranchesWasBranchedFrom(IBranch branc
180
213
if ( branch . Tip == null )
181
214
{
182
215
this . log . Warning ( $ "{ branch } has no tip.") ;
183
- yield break ;
216
+ return Enumerable . Empty < BranchCommit > ( ) ;
184
217
}
185
218
186
- DateTimeOffset ? when = null ;
187
- var branchCommits = new MergeCommitFinder ( this , configuration , excludedBranches , this . log )
188
- . FindMergeCommitsFor ( branch ) . ToList ( ) ;
189
- foreach ( var branchCommit in branchCommits )
190
- {
191
- if ( when != null && branchCommit . Commit . When != when ) break ;
192
- yield return branchCommit ;
193
- when = branchCommit . Commit . When ;
194
- }
219
+ return new MergeCommitFinder ( this , configuration , excludedBranches , this . log ) . FindMergeCommitsFor ( branch ) . ToList ( ) ;
195
220
}
196
221
}
197
222
0 commit comments