8000 Restore old Credentials API as Obsolete · GiTechLab/libgit2sharp@19cd630 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19cd630

Browse files
committed
Restore old Credentials API as Obsolete
1 parent 8cc996e commit 19cd630

File tree

7 files changed

+95
-8
lines changed

7 files changed

+95
-8
lines changed

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
109109
}
110110

111111
[Fact]
112-
public void LibGit2SharpInterfacesCoverAllPublicMembers()
112+
public void LibGit2SharpPublicInterfacesCoverAllPublicMembers()
113113
{
114114
var methodsMissingFromInterfaces =
115115
from t in Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
116116
where !t.IsInterface
117-
where t.GetInterfaces().Any(i => i.Namespace == typeof(IRepository).Namespace)
117+
where t.GetInterfaces().Any(i => i.IsPublic && i.Namespace == typeof(IRepository).Namespace)
118118
let interfaceTargetMethods = from i in t.GetInterfaces()
119119
from im in t.GetInterfaceMap(i).TargetMethods
120120
select im

LibGit2Sharp/CloneOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace LibGit2Sharp
77
/// <summary>
88
/// Options to define clone behaviour
99
/// </summary>
10-
public sealed class CloneOptions : IConvertableToGitCheckoutOpts
10+
public sealed class CloneOptions : IConvertableToGitCheckoutOpts, ICredentialsProvider
1111
{
1212
/// <summary>
1313
/// Creates default <see cref="CloneOptions"/> for a non-bare clone
@@ -41,6 +41,12 @@ public CloneOptions()
4141
/// <summary>
4242
/// Credentials to use for user/pass authentication
4343
/// </summary>
44+
[Obsolete("This will be removed in future release. Use CredentialsProvider.")]
45+
public Credentials Credentials { get; set; }
46+
47+
/// <summary>
48+
/// Handler to generate <see cref="LibGit2Sharp.Credentials"/> for authentication.
49+
/// </summary>
4450
public CredentialsHandler CredentialsProvider { get; set; }
4551

4652
#region IConvertableToGitCheckoutOpts

LibGit2Sharp/Credentials.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using LibGit2Sharp.Core;
3+
using LibGit2Sharp.Handlers;
34

45
namespace LibGit2Sharp
56
{
@@ -19,4 +20,41 @@ public abstract class Credentials
1920
/// <returns>0 for success, &lt; 0 to indicate an error, &gt; 0 to indicate no credential was acquired.</returns>
2021
protected internal abstract int GitCredentialHandler(out IntPtr cred, IntPtr url, IntPtr usernameFromUrl, GitCredentialType types, IntPtr payload);
2122
}
23+
24+
internal interface ICredentialsProvider
25+
{
26+
/// <summary>
27+
/// The <see cref="Credentials"/> to authenticate with during the push.
28+
/// </summary>
29+
[Obsolete("This will be removed in future release. Use CredentialsProvider.")]
30+
Credentials Credentials { get; }
31+
32+
/// <summary>
33+
/// Handler to generate <see cref="LibGit2Sharp.Credentials"/> for authentication.
34+
/// </summary>
35+
CredentialsHandler CredentialsProvider { get; }
36+
}
37+
38+
internal static class CredentialsProviderExtensions
39+
{
40+
public static CredentialsHandler GetCredentialsHandler(this ICredentialsProvider provider)
41+
{
42+
if (provider == null)
43+
{
44+
return null;
45+
}
46+
47+
if (provider.CredentialsProvider != null)
48+
{
49+
return provider.CredentialsProvider;
50+
}
51+
52+
if (provider.Credentials == null)
53+
{
54+
return null;
55+
}
56+
57+
return (url, user, type) => provider.Credentials;
58+
}
59+
}
2260
}

LibGit2Sharp/FetchOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace LibGit2Sharp
66
/// <summary>
77
/// Collection of parameters controlling Fetch behavior.
88
/// </summary>
9-
public sealed class FetchOptions
9+
public sealed class FetchOptions : ICredentialsProvider
1010
{
1111
/// <summary>
1212
/// Specifies the tag-following behavior of the fetch operation.
@@ -42,6 +42,12 @@ public sealed class FetchOptions
4242
/// <summary>
4343
/// Credentials to use for username/password authentication.
4444
/// </summary>
45+
[Obsolete("This will be removed in future release. Use CredentialsProvider.")]
46+
public Credentials Credentials { get; set; }
47+
48+
/// <summary>
49+
/// Handler to generate <see cref="LibGit2Sharp.Credentials"/> for authentication.
50+
/// </summary>
4551
public CredentialsHandler CredentialsProvider { get; set; }
4652
}
4753
}

LibGit2Sharp/Network.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ public virtual RemoteCollection Remotes
3636
get { return remotes.Value; }
3737
}
3838

39+
/// <summary>
40+
/// List references in a <see cref="Remote"/> repository.
41+
/// <para>
42+
/// When the remote tips are ahead of the local ones, the retrieved
43+
/// <see cref="DirectReference"/>s may point to non existing
44+
/// <see cref="GitObject"/>s in the local repository. In that
45+
/// case, <see cref="DirectReference.Target"/> will return <c>null</c>.
46+
/// </para>
47+
/// </summary>
48+
/// <param name="remote">The <see cref="Remote"/> to list from.</param>
49+
/// <param name="credentials">The optional <see cref="Credentials"/> used to connect to remote repository.</param>
50+
/// <returns>The references in the <see cref="Remote"/> repository.</returns>
51+
[Obsolete("This will be removed in future release. Use the overload ListReferences(Remote, CredentialsHandler).")]
52+
public virtual IEnumerable<DirectReference> ListReferences(Remote remote, Credentials credentials)
53+
{
54+
return ListReferences(remote,
55+
credentials == null ? null : new CredentialsHandler((url, user, type) => credentials));
56+
}
57+
3958
/// <summary>
4059
/// List references in a <see cref="Remote"/> repository.
4160
/// <para>
@@ -272,7 +291,7 @@ public virtual void Push(
272291
// Load the remote.
273292
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
274293
{
275-
var callbacks = new RemoteCallbacks(null, null, null, pushOptions.CredentialsProvider);
294+
var callbacks = new RemoteCallbacks(null, null, null, pushOptions);
276295
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
277296
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
278297

LibGit2Sharp/PushOptions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ namespace LibGit2Sharp
66
/// <summary>
77
/// Collection of parameters controlling Push behavior.
88
/// </summary>
9-
public sealed class PushOptions
9+
public sealed class PushOptions : ICredentialsProvider
1010
{
1111
/// <summary>
12-
/// The <see cref="Credentials"/> to authenticate with during the push.
12+
/// The <see cref="LibGit2Sharp.Credentials"/> to authenticate with during the push.
13+
/// </summary>
14+
[Obsolete("This will be removed in future release. Use CredentialsProvider.")]
15+
public Credentials Credentials { get; set; }
16+
17+
/// <summary>
18+
/// Handler to generate <see cref="LibGit2Sharp.Credentials"/> for authentication.
1319
/// </summary>
1420
public CredentialsHandler CredentialsProvider { get; set; }
1521

LibGit2Sharp/RemoteCallbacks.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ namespace LibGit2Sharp
1212
/// </summary>
1313
internal class RemoteCallbacks
1414
{
15+
internal RemoteCallbacks(
16+
ProgressHandler onProgress = null,
17+
TransferProgressHandler onDownloadProgress = null,
18+
UpdateTipsHandler onUpdateTips = null,
19+
ICredentialsProvider credentialsProvider = null)
20+
{
21+
Progress = onProgress;
22+
DownloadTransferProgress = onDownloadProgress;
23+
UpdateTips = onUpdateTips;
24+
CredentialsProvider = credentialsProvider.GetCredentialsHandler();
25+
}
26+
1527
internal RemoteCallbacks(
1628
ProgressHandler onProgress = null,
1729
TransferProgressHandler onDownloadProgress = null,
@@ -30,7 +42,7 @@ internal RemoteCallbacks(FetchOptions fetchOptions)
3042
Progress = fetchOptions.OnProgress;
3143
DownloadTransferProgress = fetchOptions.OnTransferProgress;
3244
UpdateTips = fetchOptions.OnUpdateTips;
33-
CredentialsProvider = fetchOptions.CredentialsProvider;
45+
CredentialsProvider = fetchOptions.GetCredentialsHandler();
3446
}
3547

3648
#region Delegates

0 commit comments

Comments
 (0)
0