如何通过libgit2sharp在本地克隆GitHub仓库? [英] how to clone GitHub repo locally via libgit2sharp?

查看:172
本文介绍了如何通过libgit2sharp在本地克隆GitHub仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写代码以编程方式通过libgit2sharp(v0.21.0.176)将GitHub私有仓库复制到本地仓库中。

I wrote code to programmatically clone a GitHub private repo to a local repo via libgit2sharp ( v0.21.0.176 )

var cloneOptions = new CloneOptions { BranchName = "master", Checkout = true };
var cloneResult = Repository.Clone( @"https://github.com/my-organization/my-repo.git", @"c:\github\my-organization\my-repo" );

抛出的异常:

exception thrown :

{LibGit2Sharp.LibGit2SharpException: Request failed with status code: 401
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)
   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

cloneResult值为空(由于引发异常从未设置)

cloneResult value is null ( never set due to exception thrown )

注意无论是否存在\my-repo \文件夹,都会抛出相同的401异常。

Note that the identical 401 exception is thrown whether or not the \my-repo\ folder is present.

函数调用语法是否正确?

Is my function call syntax correct ?

从命令行执行, git clone 首先创建一个本地dir文件夹以克隆进去。

Executed from the command line, git clone first creates a local dir folder to clone into.

是否libgit2sharp Repository.Clone()的工作方式不同?

Does libgit2sharp Repository.Clone() work differently ?

推荐答案

401是HTTP代码这意味着需要对服务器进行认证。在libgit2中有代码路径,它并不总是将这种情况正确地转换为 GIT_AUTH ,但这就是它的意思。

401 is the HTTP code meaning that you need to authenticate against the server. There are code paths in libgit2 which do not always correctly convert this situation into GIT_AUTH, but that's what it means.

当存储库不存在时,GitHub(和其他服务)也可以返回此错误,以避免泄露有关私有存储库存在的信息。

GitHub (and other services) can also return this error when the repository does not exist, as a way to avoid leaking information about the existence of private repositories.

不提供任何方式让libgit2(sharp)向你询问用户的凭证。您需要传入 CloneOptions ,您的 CredentialsProvider 设置为授权用户的凭据。

You're not providing any way for libgit2(sharp) to ask you for the user's credentials. You need to pass in CloneOptions where you have a CredentialsProvider set to an authorized user's credentials.

这篇关于如何通过libgit2sharp在本地克隆GitHub仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆