Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug: Branch names cannot contain the word 'refs' #3103 #3459

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/");
: ReferenceName.LocalBranchPrefix + currentBranch[referencePrefix.Length..];

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