libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.11k stars 876 forks source link

Unable to clone git repo while using this library. #2062

Closed Farhana0308 closed 7 months ago

Farhana0308 commented 8 months ago

I have described the issue in detail on the stackoverflow : https://stackoverflow.com/questions/77400787/git-clone-is-failing-with-error-code-503-while-using-libgit2sharp-library

Expected behavior

Git clone successful

Actual behavior

Git clone is failing with 503 error

Version of LibGit2Sharp (release number or SHA1)

0.26.2

Operating system(s) tested; .NET runtime tested

Windows 10; .Net 6

bording commented 7 months ago

@Farhana0308 Looking at the details over on Stack Overflow, it's not clear to me what you mean by " Libgit2sharp uses winhttp proxy and doesnot honour internet proxy settings"

In general, the underlying libgit2 library is going to use the proxy settings that git itself respects: either set in the .gitconfig file or the information set in the HTTP_PROXY \ HTTPS_PROXY environment variables.

Do you have your proxy information configured in that way?

Farhana0308 commented 7 months ago

@bording - Thank you for the response. We are accessing git hosted in private network and hence no proxy is required for access. There is no proxy configured in git for this reason. But winhttp proxy is present due to some unknown reason at present. libgit2sharp uses this proxy instead of direct access as git config. Is there a way to bypass winhttp proxy using libgit2sharp. We are able to access git while using NGit which we assume considers internet proxy setting unlike libgit2sharp.

Your response is highly appreciated !

siprbaum commented 7 months ago

@bording

@Farhana0308 Looking at the details over on Stack Overflow, it's not clear to me what you mean by " Libgit2sharp uses winhttp proxy and doesnot honour internet proxy settings"

In general, the underlying libgit2 library is going to use the proxy settings that git itself respects: either set in the .gitconfig file or the information set in the HTTP_PROXY \ HTTPS_PROXY environment variables.

Do you have your proxy information configured in that way?

Cloning over proxy via libgit2sharp is not possible, as there is no way to pass to libgit2 the information to use the configured proxy server via the environment variables (HTTP_PROXY / HTTPS_PROXY). We did a test ~ 2 months ago and we needed

2043 to get this working.

Farhana0308 commented 7 months ago

@bording

@Farhana0308 Looking at the details over on Stack Overflow, it's not clear to me what you mean by " Libgit2sharp uses winhttp proxy and doesnot honour internet proxy settings" In general, the underlying libgit2 library is going to use the proxy settings that git itself respects: either set in the .gitconfig file or the information set in the HTTP_PROXY \ HTTPS_PROXY environment variables. Do you have your proxy information configured in that way?

Cloning over proxy via libgit2sharp is not possible, as there is no way to pass to libgit2 the information to use the configured proxy server via the environment variables (HTTP_PROXY / HTTPS_PROXY). We did a test ~ 2 months ago and we needed #2043 to get this working.

@siprbaum - I tried the Nuget package suggested in #2043 having GitProxyOption set as Auto, still I am unable to bypass this proxy. I dont have a gitconfig set with proxy settings, libgit2sharp is considering winhttp proxy setting by default, is there a way to change this behaviour? Winhttp Proxy Setting is from organisation side, we dont have a control so need a solution to bypass this in the library. Please note : I am able to clone the repo in same system using Ngit library where I think it is considering IE http proxy setting

Farhana0308 commented 7 months ago

@bording @siprbaum - Any help on this matter is highly appreciated. We are currently blocked due to this.

bording commented 7 months ago

But winhttp proxy is present due to some unknown reason at present

Are you getting some proxy settings from auto-configured through network settings or something like that? If you run netsh winhttp show proxy from the command line, what do you see there?

On Windows, the underlying libgit2 library that LibGit2Sharp is built on uses WinHTTP, but only adds proxy settings itself if the git config is configured for a proxy (depending on the libgit2 git proxy options). However, if some external source is adding proxy settings to WinHTTP, then it does make sense that LibGit2Sharp would attempt to use that proxy.

If you have a way to remove the WinHTTP proxy settings, perhaps via netsh winhttp set proxy, then that should get you unstuck for how.

The good news is that libgit2 1.7 just added a new Windows Schannel http option, meaning it would no longer pick up any external WinHTTP proxy settings.

I've started looking into trying to get LibGit2Sharp updated to use that, but I've run into a few roadblocks that I need to work through first. See #2064 if you're interested in some of those details.

I'm also going to look into getting support for setting GitProxyOptions merged in so that it's actually possible to use the git config proxy options as you'd expect them to work.

Farhana0308 commented 7 months ago

But winhttp proxy is present due to some unknown reason at present

Are you getting some proxy settings from auto-configured through network settings or something like that? If you run netsh winhttp show proxy from the command line, what do you see there?

On Windows, the underlying libgit2 library that LibGit2Sharp is built on uses WinHTTP, but only adds proxy settings itself if the git config is configured for a proxy (depending on the libgit2 git proxy options). However, if some external source is adding proxy settings to WinHTTP, then it does make sense that LibGit2Sharp would attempt to use that proxy.

If you have a way to remove the WinHTTP proxy settings, perhaps via netsh winhttp set proxy, then that should get you unstuck for how.

The good news is that libgit2 1.7 just added a new Windows Schannel http option, meaning it would no longer pick up any external WinHTTP proxy settings.

I've started looking into trying to get LibGit2Sharp updated to use that, but I've run into a few roadblocks that I need to work through first. See #2064 if you're interested in some of those details.

I'm also going to look into getting support for setting GitProxyOptions merged in so that it's actually possible to use the git config proxy options as you'd expect them to work.

Thank you @bording for the response and for making the changes. As you rightly said with this new change, external winhttp proxy is not considered and we are able to proceed. Thanks again !

Farhana0308 commented 7 months ago

Closing this issue as it got addressed with the latest library release.

bording commented 7 months ago

LibGit2Sharp 0.29.0 has been released, which includes the above mentioned libgit2 WinHTTP changes and adds proxy options to make proxies fully configurable.