Skip to content

Commit 5eba657

Browse files
committed
Added certificateCheck parameter to Repository.ListRemoteReferences and Network.ListReferencesInternal functions
1 parent 8276589 commit 5eba657

File tree

2 files changed

+67
-17
lines changed

2 files changed

+67
-17
lines changed

LibGit2Sharp/Network.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote)
5252
{
5353
Ensure.ArgumentNotNull(remote, "remote");
5454

55-
return ListReferencesInternal(remote.Url, null, new ProxyOptions());
55+
return ListReferencesInternal(remote.Url, null, null, new ProxyOptions());
5656
}
5757

5858
/// <summary>
@@ -71,7 +71,7 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote, ProxyOptions
7171
{
7272
Ensure.ArgumentNotNull(remote, "remote");
7373

74-
return ListReferencesInternal(remote.Url, null, proxyOptions);
74+
return ListReferencesInternal(remote.Url, null, null, proxyOptions);
7575
}
7676

7777
/// <summary>
@@ -91,7 +91,29 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsH
9191
Ensure.ArgumentNotNull(remote, "remote");
9292
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
9393

94-
return ListReferencesInternal(remote.Url, credentialsProvider, new ProxyOptions());
94+
return ListReferencesInternal(remote.Url, credentialsProvider, null, new ProxyOptions());
95+
}
96+
97+
/// <summary>
98+
/// List references in a <see cref="Remote"/> repository.
99+
/// <para>
100+
/// When the remote tips are ahead of the local ones, the retrieved
101+
/// <see cref="DirectReference"/>s may point to non existing
102+
/// <see cref="GitObject"/>s in the local repository. In that
103+
/// case, <see cref="DirectReference.Target"/> will return <c>null</c>.
104+
/// </para>
105+
/// </summary>
106+
/// <param name="remote">The <see cref="Remote"/> to list from.</param>
107+
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
108+
/// <param name="certificateCheck">This handler will be called to let the user make a decision on whether to allow the connection to proceed based on the certificate presented by the server..</param>
109+
/// <returns>The references in the <see cref="Remote"/> repository.</returns>
110+
public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsHandler credentialsProvider, CertificateCheckHandler certificateCheck)
111+
{
112+
Ensure.ArgumentNotNull(remote, "remote");
113+
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
114+
Ensure.ArgumentNotNull(certificateCheck, "certificateCheck");
115+
116+
return ListReferencesInternal(remote.Url, credentialsProvider, certificateCheck, new ProxyOptions());
95117
}
96118

97119
/// <summary>
@@ -112,7 +134,7 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsH
112134
Ensure.ArgumentNotNull(remote, "remote");
113135
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
114136

115-
return ListReferencesInternal(remote.Url, credentialsProvider, proxyOptions);
137+
return ListReferencesInternal(remote.Url, credentialsProvider, null, proxyOptions);
116138
}
117139

118140
/// <summary>
@@ -130,7 +152,7 @@ public virtual IEnumerable<Reference> ListReferences(string url)
130152
{
131153
Ensure.ArgumentNotNull(url, "url");
132154

133-
return ListReferencesInternal(url, null, new ProxyOptions());
155+
return ListReferencesInternal(url, null, null, new ProxyOptions());
134156
}
135157

136158
/// <summary>
@@ -149,7 +171,7 @@ public virtual IEnumerable<Reference> ListReferences(string url, ProxyOptions pr
149171
{
150172
Ensure.ArgumentNotNull(url, "url");
151173

152-
return ListReferencesInternal(url, null, proxyOptions);
174+
return ListReferencesInternal(url, null, null, proxyOptions);
153175
}
154176

155177
/// <summary>
@@ -169,7 +191,7 @@ public virtual IEnumerable<Reference> ListReferences(string url, CredentialsHand
169191
Ensure.ArgumentNotNull(url, "url");
170192
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
171193

172-
return ListReferencesInternal(url, credentialsProvider, new ProxyOptions());
194+
return ListReferencesInternal(url, credentialsProvider, null, new ProxyOptions());
173195
}
174196

175197
/// <summary>
@@ -190,10 +212,10 @@ public virtual IEnumerable<Reference> ListReferences(string url, CredentialsHand
190212
Ensure.ArgumentNotNull(url, "url");
191213
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
192214

193-
return ListReferencesInternal(url, credentialsProvider, new ProxyOptions());
215+
return ListReferencesInternal(url, credentialsProvider, null, new ProxyOptions());
194216
}
195217

196-
private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
218+
private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider, CertificateCheckHandler certificateCheck, ProxyOptions proxyOptions)
197219
{
198220
proxyOptions ??= new();
199221

@@ -202,9 +224,14 @@ private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHan
202224

203225
GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 };
204226

205-
if (credentialsProvider != null)
227+
if (credentialsProvider != null || certificateCheck != null)
206228
{
207-
var callbacks = new RemoteCallbacks(credentialsProvider);
229+
var fetchOptions = new FetchOptions()
230+
{
231+
CredentialsProvider = credentialsProvider,
232+
CertificateCheck = certificateCheck
233+
};
234+
var callbacks = new RemoteCallbacks(fetchOptions);
208235
gitCallbacks = callbacks.GenerateCallbacks();
209236
}
210237

LibGit2Sharp/Repository.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ internal Commit LookupCommit(string committish)
656656
/// <returns>The references in the remote repository.</returns>
657657
public static IEnumerable<Reference> ListRemoteReferences(string url)
658658
{
659-
return ListRemoteReferences(url, null, new ProxyOptions());
659+
return ListRemoteReferences(url, null, null, new ProxyOptions());
660660
}
661661

662662
/// <summary>
@@ -667,7 +667,7 @@ public static IEnumerable<Reference> ListRemoteReferences(string url)
667667
/// <returns>The references in the remote repository.</returns>
668668
public static IEnumerable<Reference> ListRemoteReferences(string url, ProxyOptions proxyOptions)
669669
{
670-
return ListRemoteReferences(url, null, proxyOptions);
670+
return ListRemoteReferences(url, null, null, proxyOptions);
671671
}
672672

673673
/// <summary>
@@ -683,7 +683,7 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, ProxyOptio
683683
/// <returns>The references in the remote repository.</returns>
684684
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider)
685685
{
686-
return ListRemoteReferences(url, credentialsProvider, new ProxyOptions());
686+
return ListRemoteReferences(url, credentialsProvider, null, new ProxyOptions());
687687
}
688688

689689
/// <summary>
@@ -696,9 +696,27 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, Credential
696696
/// </para>
697697
/// <param name="url">The url to list from.</param>
698698
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
699+
/// <param name="certificateCheck">This handler will be called to let the user make a decision on whether to allow the connection to proceed based on the certificate presented by the server..</param>
700+
/// <returns>The references in the remote repository.</returns>
701+
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider, CertificateCheckHandler certificateCheck)
702+
{
703+
return ListRemoteReferences(url, credentialsProvider, certificateCheck, new ProxyOptions());
704+
}
705+
706+
/// <summary>
707+
/// Lists the Remote Repository References.
708+
/// </summary>
709+
/// <para>
710+
/// Does not require a local Repository. The retrieved
711+
/// <see cref="IBelongToARepository.Repository"/>
712+
/// throws <see cref="InvalidOperationException"/> in this case.
713+
/// </para>
714+
/// <param name="url">The url to list from.</param>
715+
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
716+
/// <param name="certificateCheck">This handler will be called to let the user make a decision on whether to allow the connection to proceed based on the certificate presented by the server..</param>
699717
/// <param name="proxyOptions">Options for connecting through a proxy.</param>
700718
/// <returns>The references in the remote repository.</returns>
701-
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
719+
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider, CertificateCheckHandler certificateCheck, ProxyOptions proxyOptions)
702720
{
703721
Ensure.ArgumentNotNull(url, "url");
704722

@@ -710,9 +728,14 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, Credential
710728

711729
var gitCallbacks = new GitRemoteCallbacks { version = 1 };
712730

713-
if (credentialsProvider != null)
731+
if (credentialsProvider != null || certificateCheck != null)
714732
{
715-
var callbacks = new RemoteCallbacks(credentialsProvider);
733+
var fetchOptions = new FetchOptions()
734+
{
735+
CredentialsProvider = credentialsProvider,
736+
CertificateCheck = certificateCheck
737+
};
738+
var callbacks = new RemoteCallbacks(fetchOptions);
716739
gitCallbacks = callbacks.GenerateCallbacks();
717740
}
718741

0 commit comments

Comments
 (0)