Skip to content

Commit a809171

Browse files
committed
Make branch name comparison case insensitive
1 parent 4896d89 commit a809171

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public BranchConfig GetBranchConfiguration(Branch targetBranch, Commit currentCo
4141
if (matchingBranches.Increment == IncrementStrategy.Inherit)
4242
{
4343
matchingBranches = InheritBranchConfiguration(targetBranch, matchingBranches, currentCommit, configuration, excludedInheritBranches);
44-
if (matchingBranches.Name == FallbackConfigName && matchingBranches.Increment == IncrementStrategy.Inherit)
44+
if (matchingBranches.Name.IsEquivalentTo(FallbackConfigName) && matchingBranches.Increment == IncrementStrategy.Inherit)
4545
{
4646
// We tried, and failed to inherit, just fall back to patch
4747
matchingBranches.Increment = IncrementStrategy.Patch;
@@ -152,7 +152,7 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
152152

153153
var inheritingBranchConfig = GetBranchConfiguration(chosenBranch, currentCommit, configuration, excludedInheritBranches);
154154
var configIncrement = inheritingBranchConfig.Increment;
155-
if (inheritingBranchConfig.Name == FallbackConfigName && configIncrement == IncrementStrategy.Inherit)
155+
if (inheritingBranchConfig.Name.IsEquivalentTo(FallbackConfigName) && configIncrement == IncrementStrategy.Inherit)
156156
{
157157
log.Warning("Fallback config inherits by default, dropping to patch increment");
158158
configIncrement = IncrementStrategy.Patch;

src/GitVersionCore/Core/GitPreparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
271271
const string moveBranchMsg = "Move one of the branches along a commit to remove warning";
272272

273273
log.Warning($"Found more than one local branch pointing at the commit '{headSha}' ({csvNames}).");
274-
var master = localBranchesWhereCommitShaIsHead.SingleOrDefault(n => n.FriendlyName == "master");
274+
var master = localBranchesWhereCommitShaIsHead.SingleOrDefault(n => n.FriendlyName.IsEquivalentTo("master"));
275275
if (master != null)
276276
{
277277
log.Warning("Because one of the branches is 'master', will build master." + moveBranchMsg);

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.IsEquivalentTo(targetBranch) ||
188+
b.FriendlyName.IsEquivalentTo(targetBranch) ||
189+
b.NameWithoutRemote().IsEquivalentTo(targetBranch));
190190

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

src/GitVersionCore/Extensions/LibGitExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static bool IsSameBranch(this Branch branch, Branch otherBranch)
3838
var otherBranchFriendlyName = otherBranch.NameWithoutRemote();
3939
var branchFriendlyName = branch.NameWithoutRemote();
4040

41-
return otherBranchFriendlyName == branchFriendlyName;
41+
return otherBranchFriendlyName.IsEquivalentTo(branchFriendlyName);
4242
}
4343

4444
/// <summary>

src/GitVersionCore/Extensions/RepositoryExtensions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void EnsureLocalBranchExistsForCurrentBranch(this IRepository repo
6868

6969
var repoTipId = repoTip.Id;
7070

71-
if (repo.Branches.All(b => b.CanonicalName != localCanonicalName))
71+
if (repo.Branches.All(b => !b.CanonicalName.IsEquivalentTo(localCanonicalName)))
7272
{
7373
log.Info(isBranch ? $"Creating local branch {localCanonicalName}"
7474
: $"Creating local branch {localCanonicalName} pointing at {repoTipId}");
@@ -156,17 +156,20 @@ public static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(this IRepos
156156
{
157157
var prefix = $"refs/remotes/{remoteName}/";
158158
var remoteHeadCanonicalName = $"{prefix}HEAD";
159+
var remoteTrackingReferences = repo.Refs
160+
.FromGlob(prefix + "*")
161+
.Where(r => !r.CanonicalName.IsEquivalentTo(remoteHeadCanonicalName));
159162

160-
foreach (var remoteTrackingReference in repo.Refs.FromGlob(prefix + "*").Where(r => r.CanonicalName != remoteHeadCanonicalName))
163+
foreach (var remoteTrackingReference in remoteTrackingReferences)
161164
{
162165
var remoteTrackingReferenceName = remoteTrackingReference.CanonicalName;
163166
var branchName = remoteTrackingReferenceName.Substring(prefix.Length);
164167
var localCanonicalName = "refs/heads/" + branchName;
165168

166169
// We do not want to touch our current branch
167-
if (branchName == repo.Head.FriendlyName) continue;
170+
if (branchName.IsEquivalentTo(repo.Head.FriendlyName)) continue;
168171

169-
if (repo.Refs.Any(x => x.CanonicalName == localCanonicalName))
172+
if (repo.Refs.Any(x => x.CanonicalName.IsEquivalentTo(localCanonicalName)))
170173
{
171174
var localRef = repo.Refs[localCanonicalName];
172175
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 IsEquivalentTo(this string self, string other)
134+
{
135+
return String.Equals(self, other, StringComparison.OrdinalIgnoreCase);
136+
}
132137
}
133138
}

src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void UpdatePreReleaseTag(SemanticVersion semanticVersion, string branchN
109109

110110
var lastTag = repositoryMetadataProvider
111111
.GetVersionTagsOnBranch(context.CurrentBranch, context.Configuration.GitTagPrefix)
112-
.FirstOrDefault(v => v.PreReleaseTag.Name == tagToUse);
112+
.FirstOrDefault(v => v.PreReleaseTag.Name.IsEquivalentTo(tagToUse));
113113

114114
if (lastTag != null &&
115115
MajorMinorPatchEqual(lastTag, semanticVersion) &&

0 commit comments

Comments
 (0)