Skip to content

Commit c8f17be

Browse files
committed
Make comparison of CanonicalName case insensitive
1 parent c6d8764 commit c8f17be

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/GitVersionCore/Core/RepositoryMetadataProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ public Branch GetTargetBranch(string targetBranch)
184184
// In the case where HEAD is not the desired branch, try to find the branch with matching name
185185
desiredBranch = repository.Branches?
186186
.SingleOrDefault(b =>
187-
b.CanonicalName == targetBranch ||
188-
b.FriendlyName == targetBranch ||
189-
b.NameWithoutRemote() == targetBranch);
187+
b.CanonicalName.EquivalentTo(targetBranch) ||
188+
b.FriendlyName.EquivalentTo(targetBranch) ||
189+
b.NameWithoutRemote().EquivalentTo(targetBranch));
190190

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

src/GitVersionCore/Extensions/RepositoryExtensions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void EnsureLocalBranchExistsForCurrentBranch(this IRepository repo
5454

5555
var repoTipId = repoTip.Id;
5656

57-
if (repo.Branches.All(b => b.CanonicalName != localCanonicalName))
57+
if (repo.Branches.All(b => !String.Equals(b.CanonicalName, localCanonicalName, StringComparison.OrdinalIgnoreCase)))
5858
{
5959
log.Info(isBranch ? $"Creating local branch {localCanonicalName}"
6060
: $"Creating local branch {localCanonicalName} pointing at {repoTipId}");
@@ -142,8 +142,11 @@ public static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(this IRepos
142142
{
143143
var prefix = $"refs/remotes/{remoteName}/";
144144
var remoteHeadCanonicalName = $"{prefix}HEAD";
145+
var remoteTrackingReferences = repo.Refs
146+
.FromGlob(prefix + "*")
147+
.Where(r => !r.CanonicalName.EquivalentTo(remoteHeadCanonicalName));
145148

146-
foreach (var remoteTrackingReference in repo.Refs.FromGlob(prefix + "*").Where(r => r.CanonicalName != remoteHeadCanonicalName))
149+
foreach (var remoteTrackingReference in remoteTrackingReferences)
147150
{
148151
var remoteTrackingReferenceName = remoteTrackingReference.CanonicalName;
149152
var branchName = remoteTrackingReferenceName.Substring(prefix.Length);
@@ -152,7 +155,7 @@ public static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(this IRepos
152155
// We do not want to touch our current branch
153156
if (branchName == repo.Head.FriendlyName) continue;
154157

155-
if (repo.Refs.Any(x => x.CanonicalName == localCanonicalName))
158+
if (repo.Refs.Any(x => x.CanonicalName.EquivalentTo(localCanonicalName)))
156159
{
157160
var localRef = repo.Refs[localCanonicalName];
158161
var remotedirectReference = remoteTrackingReference.ResolveToDirectReference();

src/GitVersionCore/Extensions/StringExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,10 @@ public static string RegexReplace(this string input, string pattern, string repl
129129
{
130130
return Regex.Replace(input, pattern, replace, options);
131131
}
132+
133+
public static bool EquivalentTo(this string self, string other)
134+
{
135+
return String.Equals(self, other, StringComparison.OrdinalIgnoreCase);
136+
}
132137
}
133138
}

0 commit comments

Comments
 (0)