From 246fe921ca50b5c6d8cc5321b1c993de6fd6f374 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Tue, 22 Mar 2016 06:30:26 +0100 Subject: [PATCH 1/2] 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. --- LibGit2Sharp/Branch.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index dbb1dd9ec..0bb3b993e 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -153,6 +153,26 @@ public virtual string UpstreamBranchCanonicalName } } + /// + /// Get the name of the remote for the branch. + /// + /// If this is a local branch, this will return the configured + /// to fetch from and push to. If this is a + /// remote-tracking branch, this will return the name of the remote + /// containing the tracked branch. If there no tracking information + /// this will return null. + /// + /// + public virtual string RemoteName + { + get + { + return IsRemote + ? RemoteNameFromRemoteTrackingBranch() + : RemoteNameFromLocalBranch(); + } + } + /// /// Get the remote for the branch. /// @@ -166,16 +186,7 @@ public virtual Remote Remote { get { - string remoteName; - - if (IsRemote) - { - remoteName = RemoteNameFromRemoteTrackingBranch(); - } - else - { - remoteName = RemoteNameFromLocalBranch(); - } + string remoteName = RemoteName; if (remoteName == null) { From 9a408b93614e16b1e27a3598a346d26c84093068 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Tue, 22 Mar 2016 17:42:38 +0100 Subject: [PATCH 2/2] Deprecate the Remote property on Branch --- LibGit2Sharp/Branch.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index 0bb3b993e..dd2d4fa6c 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -182,6 +182,7 @@ public virtual string RemoteName /// the tracked branch. /// /// + [Obsolete("This property is deprecated. Use Repository.Network.Remotes[] using the RemoteName property")] public virtual Remote Remote { get