From ca5297b7a0c0b2f4a003ef1adafb04cc4d1a8acb Mon Sep 17 00:00:00 2001 From: Jwo Nagel Date: Wed, 21 Aug 2019 16:25:17 +0200 Subject: [PATCH 1/4] Added Factory for ProxyOptions --- LibGit2Sharp/Commands/Fetch.cs | 2 +- LibGit2Sharp/Core/GitProxyOptions.cs | 12 ++++++++++++ LibGit2Sharp/Network.cs | 4 ++-- LibGit2Sharp/Repository.cs | 4 ++-- LibGit2Sharp/SubmoduleCollection.cs | 4 +++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs index d61fca5a5..530683f92 100644 --- a/LibGit2Sharp/Commands/Fetch.cs +++ b/LibGit2Sharp/Commands/Fetch.cs @@ -75,7 +75,7 @@ public static void Fetch(Repository repository, string remote, IEnumerable ListReferencesInternal(string url, CredentialsHan using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url)) { GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 }; - GitProxyOptions proxyOptions = new GitProxyOptions { Version = 1 }; + GitProxyOptions proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); if (credentialsProvider != null) { @@ -375,7 +375,7 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp { PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism, RemoteCallbacks = gitCallbacks, - ProxyOptions = new GitProxyOptions { Version = 1 }, + ProxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions() }); } } diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index b6399af45..b6f1f2984 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -678,7 +678,7 @@ public static IEnumerable ListRemoteReferences(string url, Credential using (RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url)) { var gitCallbacks = new GitRemoteCallbacks { version = 1 }; - var proxyOptions = new GitProxyOptions { Version = 1 }; + var proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); if (credentialsProvider != null) { @@ -768,7 +768,7 @@ public static string Clone(string sourceUrl, string workdirPath, var gitCheckoutOptions = checkoutOptionsWrapper.Options; var gitFetchOptions = fetchOptionsWrapper.Options; - gitFetchOptions.ProxyOptions = new GitProxyOptions { Version = 1 }; + gitFetchOptions.ProxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options).GenerateCallbacks(); if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null) { diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs index fc508107a..8cc33f055 100644 --- a/LibGit2Sharp/SubmoduleCollection.cs +++ b/LibGit2Sharp/SubmoduleCollection.cs @@ -100,11 +100,13 @@ public virtual void Update(string name, SubmoduleUpdateOptions options) var remoteCallbacks = new RemoteCallbacks(options); var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks(); + var proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); + var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions { Version = 1, CheckoutOptions = gitCheckoutOptions, - FetchOptions = new GitFetchOptions { ProxyOptions = new GitProxyOptions { Version = 1 }, RemoteCallbacks = gitRemoteCallbacks }, + FetchOptions = new GitFetchOptions { ProxyOptions = proxyOptions/*ProxyOptions = new GitProxyOptions { Version = 1 }*/, RemoteCallbacks = gitRemoteCallbacks }, CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE }; From a47e63c09317012dbb55bd0ca6477e8c272f1452 Mon Sep 17 00:00:00 2001 From: Jwo Nagel Date: Wed, 21 Aug 2019 16:37:16 +0200 Subject: [PATCH 2/4] Removed comment --- LibGit2Sharp/SubmoduleCollection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs index 8cc33f055..31d8ab9e2 100644 --- a/LibGit2Sharp/SubmoduleCollection.cs +++ b/LibGit2Sharp/SubmoduleCollection.cs @@ -106,7 +106,7 @@ public virtual void Update(string name, SubmoduleUpdateOptions options) { Version = 1, CheckoutOptions = gitCheckoutOptions, - FetchOptions = new GitFetchOptions { ProxyOptions = proxyOptions/*ProxyOptions = new GitProxyOptions { Version = 1 }*/, RemoteCallbacks = gitRemoteCallbacks }, + FetchOptions = new GitFetchOptions { ProxyOptions = proxyOptions, RemoteCallbacks = gitRemoteCallbacks }, CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE }; From dc93d9d35197197102467f7012f398b7e349f9a7 Mon Sep 17 00:00:00 2001 From: Jwo Nagel Date: Mon, 16 Dec 2019 15:47:52 +0100 Subject: [PATCH 3/4] Added ProxyOptions Added configurable Proxyoptions to all commands connecting to a remote --- LibGit2Sharp/Commands/Fetch.cs | 2 +- LibGit2Sharp/Core/GitProxyOptions.cs | 19 +++++++++++--- LibGit2Sharp/FetchOptionsBase.cs | 10 +++++++ LibGit2Sharp/Network.cs | 4 +-- LibGit2Sharp/ProxyOptions.cs | 39 ++++++++++++++++++++++++++++ LibGit2Sharp/PushOptions.cs | 8 ++++++ LibGit2Sharp/RemoteOptions.cs | 16 ++++++++++++ LibGit2Sharp/Repository.cs | 7 ++--- LibGit2Sharp/SubmoduleCollection.cs | 2 +- 9 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 LibGit2Sharp/ProxyOptions.cs create mode 100644 LibGit2Sharp/RemoteOptions.cs diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs index 530683f92..95242aab6 100644 --- a/LibGit2Sharp/Commands/Fetch.cs +++ b/LibGit2Sharp/Commands/Fetch.cs @@ -75,7 +75,7 @@ public static void Fetch(Repository repository, string remote, IEnumerable public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; } + + /// + /// Configures operating behind a proxy + /// + /// If not set, any proxy settings will be ignored + /// + /// + public ProxyOptions ProxyOptions { get; set; } } + + } diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 310df75f3..22c3e054a 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -118,7 +118,7 @@ private IEnumerable ListReferencesInternal(string url, CredentialsHan using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url)) { GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 }; - GitProxyOptions proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); + GitProxyOptions proxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(null); if (credentialsProvider != null) { @@ -375,7 +375,7 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp { PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism, RemoteCallbacks = gitCallbacks, - ProxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions() + ProxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(pushOptions.ProxyOptions) }); } } diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs new file mode 100644 index 000000000..9d90c3cc2 --- /dev/null +++ b/LibGit2Sharp/ProxyOptions.cs @@ -0,0 +1,39 @@ +namespace LibGit2Sharp +{ + /// + /// Collection of parameters controlling proxy behavior. + /// + public class ProxyOptions + { + /// + /// The type of proxy to use, by URL, auto-detect. + /// + public ProxyType ProxyType { get; set; } + + /// + /// The URL of the proxy. (ProxyType must be Specified) + /// + public string Url { get; set; } + } + + /// + /// The type of proxy to use. + /// + public enum ProxyType + { + /// + /// Do not attempt to connect through a proxy + /// If built against libcurl, it itself may attempt to connect + /// to a proxy if the environment variables specify it. + /// + None = 0, + /// + /// Try to auto-detect the proxy from the git configuration. + /// + Auto = 1, + /// + /// Connect via the URL given in the options + /// + Specified = 2 + } +} diff --git a/LibGit2Sharp/PushOptions.cs b/LibGit2Sharp/PushOptions.cs index b5afc3eb2..03da3170b 100644 --- a/LibGit2Sharp/PushOptions.cs +++ b/LibGit2Sharp/PushOptions.cs @@ -51,5 +51,13 @@ public sealed class PushOptions /// information about what updates will be performed. /// public PrePushHandler OnNegotiationCompletedBeforePush { get; set; } + + /// + /// Configures operating behind a proxy + /// + /// If not set, any proxy settings will be ignored + /// + /// + public ProxyOptions ProxyOptions { get; set; } } } diff --git a/LibGit2Sharp/RemoteOptions.cs b/LibGit2Sharp/RemoteOptions.cs new file mode 100644 index 000000000..53d2a1cb4 --- /dev/null +++ b/LibGit2Sharp/RemoteOptions.cs @@ -0,0 +1,16 @@ +namespace LibGit2Sharp +{ + /// + /// Collection of parameters controlling reote behavior. + /// + public class RemoteOptions + { + /// + /// Configures operating behind a proxy + /// + /// If not set, any proxy settings will be ignored + /// + /// + public ProxyOptions ProxyOptions { get; set; } + } +} diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index b6f1f2984..2824b4ff3 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -669,8 +669,9 @@ public static IEnumerable ListRemoteReferences(string url) /// /// The url to list from. /// The used to connect to remote repository. + /// Options for remote behaviore /// The references in the remote repository. - public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider) + public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider, RemoteOptions options = null) { Ensure.ArgumentNotNull(url, "url"); @@ -678,7 +679,7 @@ public static IEnumerable ListRemoteReferences(string url, Credential using (RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url)) { var gitCallbacks = new GitRemoteCallbacks { version = 1 }; - var proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); + var proxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(options?.ProxyOptions); if (credentialsProvider != null) { @@ -768,7 +769,7 @@ public static string Clone(string sourceUrl, string workdirPath, var gitCheckoutOptions = checkoutOptionsWrapper.Options; var gitFetchOptions = fetchOptionsWrapper.Options; - gitFetchOptions.ProxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); + gitFetchOptions.ProxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(options.ProxyOptions); gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options).GenerateCallbacks(); if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null) { diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs index 31d8ab9e2..db0b38127 100644 --- a/LibGit2Sharp/SubmoduleCollection.cs +++ b/LibGit2Sharp/SubmoduleCollection.cs @@ -100,7 +100,7 @@ public virtual void Update(string name, SubmoduleUpdateOptions options) var remoteCallbacks = new RemoteCallbacks(options); var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks(); - var proxyOptions = GitProxyOptionsFactory.CreateDefaultProxyOptions(); + var proxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(options.ProxyOptions); var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions { From a2e15e6cab24b25ab81be189b8f236dc3e088477 Mon Sep 17 00:00:00 2001 From: Jwo Nagel Date: Tue, 17 Dec 2019 14:43:09 +0000 Subject: [PATCH 4/4] Resolved Testissues --- LibGit2Sharp/LibGit2Sharp.csproj | 1 + LibGit2Sharp/ProxyOptions.cs | 8 +++++++- LibGit2Sharp/RemoteOptions.cs | 8 +++++++- LibGit2Sharp/Repository.cs | 20 ++++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index cf51b4efc..eba45fb96 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -14,6 +14,7 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true ..\libgit2sharp.snk + AnyCPU;x64;x86 diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs index 9d90c3cc2..69ded8233 100644 --- a/LibGit2Sharp/ProxyOptions.cs +++ b/LibGit2Sharp/ProxyOptions.cs @@ -3,8 +3,14 @@ /// /// Collection of parameters controlling proxy behavior. /// - public class ProxyOptions + public sealed class ProxyOptions { + /// + /// Constructor. + /// + public ProxyOptions() + { } + /// /// The type of proxy to use, by URL, auto-detect. /// diff --git a/LibGit2Sharp/RemoteOptions.cs b/LibGit2Sharp/RemoteOptions.cs index 53d2a1cb4..afaaf4328 100644 --- a/LibGit2Sharp/RemoteOptions.cs +++ b/LibGit2Sharp/RemoteOptions.cs @@ -3,8 +3,14 @@ /// /// Collection of parameters controlling reote behavior. /// - public class RemoteOptions + public sealed class RemoteOptions { + /// + /// Constructor. + /// + public RemoteOptions() + { } + /// /// Configures operating behind a proxy /// diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 2824b4ff3..094528c2b 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -669,9 +669,25 @@ public static IEnumerable ListRemoteReferences(string url) /// /// The url to list from. /// The used to connect to remote repository. - /// Options for remote behaviore /// The references in the remote repository. - public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider, RemoteOptions options = null) + public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider) + { + return ListRemoteReferences(url, credentialsProvider, new RemoteOptions()); + } + + /// + /// Lists the Remote Repository References. + /// + /// + /// Does not require a local Repository. The retrieved + /// + /// throws in this case. + /// + /// The url to list from. + /// The used to connect to remote repository. + /// Options for remote behavior + /// The references in the remote repository. + public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider, RemoteOptions options) { Ensure.ArgumentNotNull(url, "url");