【发布时间】:2021-08-05 21:58:49
【问题描述】:
我现有的 Fetch 方法如下所示。
public void Fetch(string remote) => CommandLine.Run($"git fetch {remote}", _repoFolder);
我想使用 libgit2sharp 实现相同的功能。
这是我想出的:
public void Fetch(string remote)
{
var repo = new Repository(_folder);
var options = new FetchOptions();
options.Prune = true;
options.TagFetchMode = TagFetchMode.Auto;
var refSpecs = $"+refs/heads/*:refs/remotes/{remote}/*";
Commands.Fetch(repo, remote, new [] {refSpecs}, options, "Fetching remote");
}
但是,这会失败并显示以下错误消息:
System.InvalidOperationException: 'authentication cancelled'
我也尝试过使用 libgit2sharp-ssh 包,结果是错误代码 401(未经授权的客户端)。
我认为 git 命令行工具可以工作,因为它知道如何授权访问(因为已经有一个遥控器)。如何使用 libgit2sharp 达到同样的效果?
【问题讨论】:
标签: libgit2sharp