gpt4 book ai didi

c# - 使用 LibGit2Sharp 克隆 Git 存储库超时错误

转载 作者:太空狗 更新时间:2023-10-29 13:15:51 25 4
gpt4 key购买 nike

我的组织运行自己的 GitHub 服务器和网络代理。我已经配置了 git,这样我就可以从命令行使用 github.com 和我们内部的 GitHub。但是使用 LibGit2Sharp,我无法对我们的 GitHub 服务器执行操作。 CloneOptions 中调用的唯一回调是 RepositoryOperationStarting。不会调用其他回调。我已经在下面发布了相关代码和配置(名称已更改以保持匿名)。我正在使用 NuGet 的 LibGit2Sharp v0.25.2。

使用 LibGit2Sharp 的代码。评论表明在访问我们内部的 github 时会触发哪些回调。当访问 github.com 时,所有回调都会按预期调用。

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

从命令行克隆:

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.

这是我的 git 配置的相关部分。我也尝试过使用 HTTP_PROXYHTTPS_PROXY 环境变量,但没有成功。

[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

使用 WireShark,我看到命令行 git 确实访问了我的代理服务器。但是,我使用 LibGit2Sharp 的 .NET 程序根本没有访问代理服务器。

最佳答案

Any other thoughts here? It appears LibGit2Sharp just isn't honoring the proxy information in .gitconfig

好像是这样,来自libgit2/libgit2sharp issue 1429 , 其中Brandon Ording (bording)评论:

It looks like GitProxyOptions were added in 88cf9a7, and they are being used in Commands.Fetch, as you can see here.

However, it appears that currently everywhere in the codebase, the GitProxyType of GitProxyOptions is always being initialized to 0, which is None.
Looking at the libgit2 code for git_proxy_t, it appears that None disables using any proxies.

Edward Thomson (ethomson)确认:

Yes, it does look like this is disabling proxies... The default transport on Windows (WinHTTP) does not support proxies, IIRC, so this is basically a noop there. But turning on auto support would help when libgit2 itself is built with libcurl support.

所以:commit 0d72f67f2确实提到:

proxy: don't specify the protocol in the type

We leave this up to the scheme in the url field.
The type should only tell us about whether we want a proxy and whether we want to auto-detect it.

那是对 issue 3110 的回应,一个月后涉及commit 1dc4491 ,带有代理配置示例,但带有 libgit2 和 Java 程序。

HTTP(S)_PROXY 虽然应该选择,但是:对于像您自己的 GitHub 服务器这样的内部服务,请检查您是否真的需要代理。< br/>大多数情况下,您会设置 NO_PROXY=localhost,.mycompany.com 以便在联系内部(LAN 而不是 WAN)服务器时使用任何代理。

关于c# - 使用 LibGit2Sharp 克隆 Git 存储库超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43924425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com