Skip to content

Commit 246fe92

Browse files
committed
Add a RemoteName property to avoid lookups
Sometimes all you need is the name and right now there's no way of getting it short of git_remote_lookup. While going through a lookup guarantees that the remote exists that shouldn't be the concern of the Branch, it should just let the caller know what's been configured as it's remote.
1 parent 5e683b9 commit 246fe92

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

LibGit2Sharp/Branch.cs

Lines changed: 21 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>
@@ -166,16 +186,7 @@ public virtual Remote Remote
166186
{
167187
get
168188
{
169-
string remoteName;
170-
171-
if (IsRemote)
172-
{
173-
remoteName = RemoteNameFromRemoteTrackingBranch();
174-
}
175-
else
176-
{
177-
remoteName = RemoteNameFromLocalBranch();
178-
}
189+
string remoteName = RemoteName;
179190

180191
if (remoteName == null)
181192
{

0 commit comments

Comments
 (0)