My organization runs its own GitHub server and web proxies. I have configured git so that I can work with both github.com and our internal GitHub from the command line. But using LibGit2Sharp, I cannot perform operations against our GitHub server. The only callback from CloneOptions
that is invoked is RepositoryOperationStarting
. No additional callbacks are invoked. I've posted the relevant code and configuration below (names have been changed to preserve anonymity). I am using LibGit2Sharp v0.25.2 from NuGet.
Code using LibGit2Sharp. Comments indicate which callbacks fire when hitting our internal github. When hitting github.com, all callbacks are invoked as expected.
private static void Main(string[] args)
{
var options = new CloneOptions
{
CertificateCheck = (certificate, valid, host) => true, // never called
CredentialsProvider = (url, fromUrl, types) => null, // never called
OnCheckoutProgress = (path, steps, totalSteps) => { }, // never called
OnProgress = output => true, // never called
OnTransferProgress = progress => true, // never called
OnUpdateTips = (name, id, newId) => true, // never called
RepositoryOperationCompleted = context => { }, // never called
RepositoryOperationStarting = context => true // ONLY THIS ONE IS CALLED
};
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; // never called
Repository.Clone(args[0], args[1], options);
}
Exception:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: failed to send request: The operation timed out
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 136
at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 354
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 715
at gitex.Program.Main(String[] args) in D:\dev\mgunter\gitex\gitex\Program.cs:line 71
Cloning from the command-line works:
C:\> git clone https://github.my-domain.com/organization/project
Cloning into 'project'...
remote: Counting objects: 1373, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 1373 (delta 8), reused 0 (delta 0), pack-reused 1350R
Receiving objects: 100% (1373/1373), 383.10 KiB | 0 bytes/s, done.
Resolving deltas: 100% (862/862), done.
Here are the relevant pieces of my git config. I have also tried with HTTP_PROXY
and HTTPS_PROXY
environment variables, but no luck.
[http "https://github.my-domain.com"]
proxy = http://proxy-for-internal.my-domain.com:80
[http "https://github.com"]
proxy = http://proxy-for-external.my-domain.com:81
sslCAinfo = ~/certificates/my-domain-root-ca.cer
[credential]
helper = wincred
[hub]
host = github.my-domain.com
protocol = https
Using WireShark, I see that command-line git
does indeed hit my proxy server. However, my .NET program using LibGit2Sharp does not hit the proxy server at all.
var co = new CloneOptions();
– Recordingvar co = new CloneOptions(); co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = "Username", Password = "Password" }; Repository.Clone("https://github.com/libgit2/libgit2sharp.git", "path/to/repo", co);
– Recording.git
on your code – RecordingServicePointManager
related callback in case it is a certificate issue? – RestrainedServicePointManager.ServerCertificateValidationCallback
, but it's not invoked either. – Provinciality.gitconfig
. – Provinciality