Skip to content

Commit 587cf54

Browse files
committed
Teach Network.ListReferences to accept both a url and a CredentialsProvider
1 parent 40f9a9c commit 587cf54

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

LibGit2Sharp/Network.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,36 @@ public virtual IEnumerable<DirectReference> ListReferences(Remote remote, Creden
9696
/// <param name="url">The url to list from.</param>
9797
/// <returns>The references in the remote repository.</returns>
9898
public virtual IEnumerable<DirectReference> ListReferences(string url)
99+
{
100+
return ListReferences(url, null);
101+
}
102+
103+
/// <summary>
104+
/// List references in a remote repository.
105+
/// <para>
106+
/// When the remote tips are ahead of the local ones, the retrieved
107+
/// <see cref="DirectReference"/>s may point to non existing
108+
/// <see cref="GitObject"/>s in the local repository. In that
109+
/// case, <see cref="DirectReference.Target"/> will return <c>null</c>.
110+
/// </para>
111+
/// </summary>
112+
/// <param name="url">The url to list from.</param>
113+
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
114+
/// <returns>The references in the remote repository.</returns>
115+
public virtual IEnumerable<DirectReference> ListReferences(string url, CredentialsHandler credentialsProvider)
99116
{
100117
Ensure.ArgumentNotNull(url, "url");
101118

102119
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_create_anonymous(repository.Handle, url))
103120
{
104121
GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 };
122+
123+
if (credentialsProvider != null)
124+
{
125+
var callbacks = new RemoteCallbacks(credentialsProvider);
126+
gitCallbacks = callbacks.GenerateCallbacks();
127+
}
128+
105129
Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks);
106130
return Proxy.git_remote_ls(repository, remoteHandle);
107131
}

0 commit comments

Comments
 (0)