Skip to content

Commit 1ef74f4

Browse files
authored
Merge pull request #3459 from HHobeck/feature/3103_branch-name-cannot-contains-the-word-refs
Fix Bug: Branch names cannot contain the word 'refs' #3103
2 parents f1ced75 + 0acceaf commit 1ef74f4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/GitVersion.Core/Core/GitPreparer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,19 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
356356
}
357357
}
358358

359-
public void EnsureLocalBranchExistsForCurrentBranch(IRemote? remote, string? currentBranch)
359+
public void EnsureLocalBranchExistsForCurrentBranch(IRemote remote, string? currentBranch)
360360
{
361361
remote.NotNull();
362362

363363
if (currentBranch.IsNullOrEmpty()) return;
364364

365-
var isRef = currentBranch.Contains("refs");
366-
var isBranch = currentBranch.Contains("refs/heads");
367-
var localCanonicalName = !isRef
368-
? "refs/heads/" + currentBranch
369-
: isBranch
365+
var referencePrefix = "refs/";
366+
var isLocalBranch = currentBranch.StartsWith(ReferenceName.LocalBranchPrefix);
367+
var localCanonicalName = !currentBranch.StartsWith(referencePrefix)
368+
? ReferenceName.LocalBranchPrefix + currentBranch
369+
: isLocalBranch
370370
? currentBranch
371-
: currentBranch.Replace("refs/", "refs/heads/");
371+
: ReferenceName.LocalBranchPrefix + currentBranch[referencePrefix.Length..];
372372

373373
var repoTip = this.repository.Head.Tip;
374374

@@ -387,14 +387,14 @@ public void EnsureLocalBranchExistsForCurrentBranch(IRemote? remote, string? cur
387387
var referenceName = ReferenceName.Parse(localCanonicalName);
388388
if (this.repository.Branches.All(b => !b.Name.Equals(referenceName)))
389389
{
390-
this.log.Info(isBranch
390+
this.log.Info(isLocalBranch
391391
? $"Creating local branch {referenceName}"
392392
: $"Creating local branch {referenceName} pointing at {repoTipId}");
393393
this.repository.Refs.Add(localCanonicalName, repoTipId.Sha);
394394
}
395395
else
396396
{
397-
this.log.Info(isBranch
397+
this.log.Info(isLocalBranch
398398
? $"Updating local branch {referenceName} to point at {repoTipId}"
399399
: $"Updating local branch {referenceName} to match ref {currentBranch}");
400400
var localRef = this.repository.Refs[localCanonicalName];

0 commit comments

Comments
 (0)