Skip to content

Commit 735a1dd

Browse files
committed
Use NameWithoutRemote() instead of FriendlyName
1 parent 3f4850d commit 735a1dd

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ static Branch[] CalculateWhenMultipleParents(IRepository repository, Commit curr
192192
}
193193
else if (branches.Count > 1)
194194
{
195-
currentBranch = branches.FirstOrDefault(b => b.FriendlyName == "master") ?? branches.First();
195+
currentBranch = branches.FirstOrDefault(b => b.NameWithoutRemote() == "master") ?? branches.First();
196196
}
197197
else
198198
{
199199
var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList();
200200
if (possibleTargetBranches.Count > 1)
201201
{
202-
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.FriendlyName == "master") ?? possibleTargetBranches.First();
202+
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.NameWithoutRemote() == "master") ?? possibleTargetBranches.First();
203203
}
204204
else
205205
{

src/GitVersionCore/GitVersionContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ private static Branch GetTargetBranch(IRepository repository, string targetBranc
169169
desiredBranch = repository?.Branches?
170170
.SingleOrDefault(b =>
171171
b.CanonicalName == targetBranch ||
172-
b.FriendlyName == targetBranch);
172+
b.FriendlyName == targetBranch ||
173+
b.NameWithoutRemote() == targetBranch);
173174

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

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ public static void CheckoutFilesIfExist(this IRepository repository, params stri
135135

136136
public static Branch FindBranch(this IRepository repository, string branchName)
137137
{
138-
var exact = repository.Branches.FirstOrDefault(x => x.FriendlyName == branchName);
139-
if (exact != null)
140-
{
141-
return exact;
142-
}
143-
144-
return repository.Branches.FirstOrDefault(x => x.FriendlyName == "origin/" + branchName);
138+
return repository.Branches.FirstOrDefault(x => x.NameWithoutRemote() == branchName);
145139
}
146140

147141
public static void DumpGraph(this IRepository repository, Action<string> writer = null, int? maxCommits = null)

0 commit comments

Comments
 (0)