Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git network operations behind corporate firewall using LibGit2Sharp throws

I am trying to use LibGit2Sharp to git push origin using the following

using(var repo = new Repository("path\to\repo\.git"))
{
   var commit = repo.Commit("Commit message", author, committer);

   var options = new PushOptions{ CredentialsProvider = (u, s, t) => new UserNamePasswordCredentials { Username = "username", Password = "password" } };
   repo.Network.Push(repo.Branches("master"), options); 
}

I get a LibGit2SharpException saying

Additional information: Failed to set proxy: The parameter is incorrect.

But in git bash everything is fine when I do git push origin.

We have NTLM proxy at work, and I am pushing to an intranet https remote URI. I have configured the proxy as http://username:[email protected]:80 in the following:

  • Env vars: HTTP_PROXY & HTTPS_PROXY
  • repos .git/config:
    • remote.origin.proxy
    • http.proxy
    • https.proxy
    • http.sslCAInfo & https.sslCAInfo - this is the path to the root CA for the host

Having read through this SO and links there it seems like libgit2sharp should find the proxy parameter just fine. Has anyone gotten this to work behing ntlm?

I am using: Windows 7, LibGit2Sharp.0.22.0, Git 2.10.1.windows.1, bash 4.3.46, .net4.5.2

Any ideas/tricks on achieving the push through an alternative are greatly welcome too!

like image 892
aateeque Avatar asked Oct 29 '22 19:10

aateeque


1 Answers

This comes from "libgit2 src/transports/winhttp.c", which calls directly the Windows API WinHttpSetOption function.

It passes an WINHTTP_OPTION_PROXY to set or retrieves an WINHTTP_PROXY_INFO structure that contains the proxy data on an existing session handle or request handle.

That function returns ERROR_INVALID_PARAMETER (A parameter is not valid) only if WINHTTP_OPTION_WEB_SOCKET_KEEPALIVE_INTERVAL is set to a value lower than 15000.

I don't know why LibGit2Sharp has that issue but try first only set the environment variables HTTP_PROXY & HTTPS_PROXY (not http.proxy & https.proxy), and make sure to use the same http url for both proxy environment variables (not https url for HTTPS_PROXY)

The official libgit2 bug on this is issue 2106, which is supposed to be resolved with PR 3110, and commit 1dc4491.
However, that fix is not part of a release yet.

like image 91
VonC Avatar answered Jan 02 '23 21:01

VonC