我的组织运行自己的GitHub服务器和web代理。我已经配置了git,以便可以从命令行使用github.com和内部GitHub。但是使用LibGit2Sharp,我不能对我们的GitHub服务器执行操作。从CloneOptions调用的唯一回调是RepositoryOperationStarting。不调用其他回调。我已经张贴了相关的代码和配置如下(名称已更改,以保持匿名)。我使用的是LibGit2Sharp v0.25.2来自NuGet。
使用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);
}例外:
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_PROXY和HTTPS_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确实击中了我的代理服务器。但是,我使用.NET的LibGit2Sharp程序根本没有击中代理服务器。
发布于 2018-10-13 04:44:49
这里还有其他想法吗?看来LibGit2Sharp只是不尊重
.gitconfig中的代理信息
libgit2 2/libgit2 2尖锐问题1429的情况似乎就是这样,)在这里发表了评论:
看起来,
GitProxyOptions是在88cf9a7中添加的,它们正在Commands.Fetch、正如你在这里看到的中使用。 然而,目前在代码库中,GitProxyTypeofGitProxyOptions似乎总是被初始化为0,即None。 查看libgit2代码git_proxy_t,似乎没有使用任何代理禁用。
)证实:
是的,看起来这是在禁用代理.Windows上的默认传输(WinHTTP)不支持代理IIRC,因此这基本上是一个noop。但是,当libgit2本身使用
libcurl支持构建时,打开自动支持会有帮助。
因此:提交0d72f67f2确实提到:
代理:不要在类型中指定协议 我们把这个留待url字段中的方案处理。 类型应该只告诉我们是否需要代理,以及是否要自动检测它。
这是对第3110期的响应,提交1dc4491在一个月后使用了代理配置示例,但是使用了libgit2和一个Java程序。
但是,应该使用HTTP(S)_PROXY,但是:对于像您自己的GitHub服务器这样的内部服务,请检查是否确实需要代理。
通常,您会设置NO_PROXY=localhost,.mycompany.com,以便在联系内部(LAN而不是WAN)服务器时不使用任何代理。
https://stackoverflow.com/questions/43924425
复制相似问题