diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs index d61fca5a5..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/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 77971ea06..6417d33bc 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -16,6 +16,7 @@ snupkg true ..\libgit2sharp.snk + AnyCPU;x64;x86 square-logo.png App_Readme/LICENSE.md diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index d5f032058..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 = new GitProxyOptions { Version = 1 }; + 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 = new GitProxyOptions { Version = 1 }, + ProxyOptions = GitProxyOptionsFactory.CreateGitProxyOptions(pushOptions.ProxyOptions) }); } } diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs new file mode 100644 index 000000000..69ded8233 --- /dev/null +++ b/LibGit2Sharp/ProxyOptions.cs @@ -0,0 +1,45 @@ +namespace LibGit2Sharp +{ + /// + /// Collection of parameters controlling proxy behavior. + /// + public sealed class ProxyOptions + { + /// + /// Constructor. + /// + public 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 99c65dd8b..31e617aee 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..afaaf4328 --- /dev/null +++ b/LibGit2Sharp/RemoteOptions.cs @@ -0,0 +1,22 @@ +namespace LibGit2Sharp +{ + /// + /// Collection of parameters controlling reote behavior. + /// + public sealed class RemoteOptions + { + /// + /// Constructor. + /// + public 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 721133cc6..9f7d03121 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -671,6 +671,23 @@ public static IEnumerable ListRemoteReferences(string url) /// The used to connect to remote repository. /// The references in the remote repository. 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"); @@ -678,7 +695,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.CreateGitProxyOptions(options?.ProxyOptions); if (credentialsProvider != null) { @@ -768,7 +785,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.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 fc508107a..db0b38127 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.CreateGitProxyOptions(options.ProxyOptions); + var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions { Version = 1, CheckoutOptions = gitCheckoutOptions, - FetchOptions = new GitFetchOptions { ProxyOptions = new GitProxyOptions { Version = 1 }, RemoteCallbacks = gitRemoteCallbacks }, + FetchOptions = new GitFetchOptions { ProxyOptions = proxyOptions, RemoteCallbacks = gitRemoteCallbacks }, CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE };