Skip to content

Commit be2eabd

Browse files
chusemanarturcic
authored andcommitted
Take the first matching branch, preferring local
If you've got a local branch and remote branch with the same name, SingleOrDefault() throws.
1 parent 6e443ae commit be2eabd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/GitVersionCore/Core/RepositoryMetadataProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ public Branch GetTargetBranch(string targetBranch)
183183
{
184184
// In the case where HEAD is not the desired branch, try to find the branch with matching name
185185
desiredBranch = repository.Branches?
186-
.SingleOrDefault(b =>
186+
.Where(b =>
187187
b.CanonicalName.IsEquivalentTo(targetBranch) ||
188188
b.FriendlyName.IsEquivalentTo(targetBranch) ||
189-
b.NameWithoutRemote().IsEquivalentTo(targetBranch));
189+
b.NameWithoutRemote().IsEquivalentTo(targetBranch))
190+
.OrderBy(b => b.IsRemote)
191+
.FirstOrDefault();
190192

191193
// Failsafe in case the specified branch is invalid
192194
desiredBranch ??= repository.Head;

0 commit comments

Comments
 (0)