Skip to content

Commit 1f5b128

Browse files
committed
Merge pull request #1287 from libgit2/branch-remote-name
Add a RemoteName property to avoid lookups
2 parents 5e683b9 + 9a408b9 commit 1f5b128

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

LibGit2Sharp/Branch.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ public virtual string UpstreamBranchCanonicalName
153153
}
154154
}
155155

156+
/// <summary>
157+
/// Get the name of the remote for the branch.
158+
/// <para>
159+
/// If this is a local branch, this will return the configured
160+
/// <see cref="Remote"/> to fetch from and push to. If this is a
161+
/// remote-tracking branch, this will return the name of the remote
162+
/// containing the tracked branch. If there no tracking information
163+
/// this will return null.
164+
/// </para>
165+
/// </summary>
166+
public virtual string RemoteName
167+
{
168+
get
169+
{
170+
return IsRemote
171+
? RemoteNameFromRemoteTrackingBranch()
172+
: RemoteNameFromLocalBranch();
173+
}
174+
}
175+
156176
/// <summary>
157177
/// Get the remote for the branch.
158178
/// <para>
@@ -162,20 +182,12 @@ public virtual string UpstreamBranchCanonicalName
162182
/// the tracked branch.
163183
/// </para>
164184
/// </summary>
185+
[Obsolete("This property is deprecated. Use Repository.Network.Remotes[] using the RemoteName property")]
165186
public virtual Remote Remote
166187
{
167188
get
168189
{
169-
string remoteName;
170-
171-
if (IsRemote)
172-
{
173-
remoteName = RemoteNameFromRemoteTrackingBranch();
174-
}
175-
else
176-
{
177-
remoteName = RemoteNameFromLocalBranch();
178-
}
190+
string remoteName = RemoteName;
179191

180192
if (remoteName == null)
181193
{

0 commit comments

Comments
 (0)