Skip to content

Commit

Permalink
Merge pull request #3459 from HHobeck/feature/3103_branch-name-cannot…
Browse files Browse the repository at this point in the history
…-contains-the-word-refs

Fix Bug: Branch names cannot contain the word 'refs' #3103
  • Loading branch information
arturcic authored Apr 4, 2023
2 parents f1ced75 + 0acceaf commit 1ef74f4
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/");
: 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

0 comments on commit 1ef74f4

Please sign in to comment.