Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b5cdef1

Browse files
authored
Merge pull request #556 from github/grokys/allow-canonical-refs
Allow canonical refs in SetTrackingBranch.
2 parents b5177b1 + f96f525 commit b5cdef1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/GitHub.App/Services/GitClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public IObservable<Unit> SetTrackingBranch(IRepository repository, string branch
8383

8484
return Observable.Defer(() =>
8585
{
86-
var remoteBranchName = "refs/remotes/" + remoteName + "/" + branchName;
86+
var remoteBranchName = IsCanonical(remoteName) ? remoteName : "refs/remotes/" + remoteName + "/" + branchName;
8787
var remoteBranch = repository.Branches[remoteBranchName];
8888
// if it's null, it's because nothing was pushed
8989
if (remoteBranch != null)
9090
{
91-
var localBranchName = "refs/heads/" + branchName;
91+
var localBranchName = IsCanonical(branchName) ? branchName : "refs/heads/" + branchName;
9292
var localBranch = repository.Branches[localBranchName];
9393
repository.Branches.Update(localBranch, b => b.TrackedBranch = remoteBranch.CanonicalName);
9494
}
@@ -108,5 +108,10 @@ public IObservable<Remote> GetHttpRemote(IRepository repo, string remote)
108108
return ret;
109109
});
110110
}
111+
112+
static bool IsCanonical(string s)
113+
{
114+
return s.StartsWith("refs/", StringComparison.Ordinal);
115+
}
111116
}
112117
}

src/GitHub.Exports.Reactive/Services/IGitClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public interface IGitClient
4545
/// Sets the remote branch that the local branch tracks
4646
/// </summary>
4747
/// <param name="repository">The repository to set</param>
48-
/// <param name="branchName">The name of the remote</param>
49-
/// <param name="remoteName">The name of the branch (local and remote)</param>
48+
/// <param name="branchName">The name of the local remote</param>
49+
/// <param name="remoteName">The name of the remote branch</param>
5050
/// <returns></returns>
5151
IObservable<Unit> SetTrackingBranch(IRepository repository, string branchName, string remoteName);
5252

0 commit comments

Comments
 (0)