Skip to content

Commit

Permalink
Fix Bug: Branch names cannot contain the word 'refs' GitTools#3103
Browse files Browse the repository at this point in the history
  • Loading branch information
HHobeck committed Apr 4, 2023
1 parent f1ced75 commit 45051d6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/GitVersion.Core/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,19 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
}
}

public void EnsureLocalBranchExistsForCurrentBranch(IRemote? remote, string? currentBranch)
public void EnsureLocalBranchExistsForCurrentBranch(IRemote remote, string? currentBranch)
{
remote.NotNull();

if (currentBranch.IsNullOrEmpty()) return;

var isRef = currentBranch.Contains("refs");
var isBranch = currentBranch.Contains("refs/heads");
var localCanonicalName = !isRef
? "refs/heads/" + currentBranch
: isBranch
var referencePrefix = "refs/";
var isLocalBranch = currentBranch.StartsWith(ReferenceName.LocalBranchPrefix);
var localCanonicalName = !currentBranch.StartsWith(referencePrefix)
? ReferenceName.LocalBranchPrefix + currentBranch
: isLocalBranch
? currentBranch
: currentBranch.Replace("refs/", "refs/heads/");
: currentBranch[referencePrefix.Length..] + ReferenceName.LocalBranchPrefix;

var repoTip = this.repository.Head.Tip;

Expand All @@ -387,14 +387,14 @@ public void EnsureLocalBranchExistsForCurrentBranch(IRemote? remote, string? cur
var referenceName = ReferenceName.Parse(localCanonicalName);
if (this.repository.Branches.All(b => !b.Name.Equals(referenceName)))
{
this.log.Info(isBranch
this.log.Info(isLocalBranch
? $"Creating local branch {referenceName}"
: $"Creating local branch {referenceName} pointing at {repoTipId}");
this.repository.Refs.Add(localCanonicalName, repoTipId.Sha);
}
else
{
this.log.Info(isBranch
this.log.Info(isLocalBranch
? $"Updating local branch {referenceName} to point at {repoTipId}"
: $"Updating local branch {referenceName} to match ref {currentBranch}");
var localRef = this.repository.Refs[localCanonicalName];
Expand Down

0 comments on commit 45051d6

Please sign in to comment.