LibGit2Sharp和TFS Git存储库 [英] LibGit2Sharp and TFS Git repository

查看:106
本文介绍了LibGit2Sharp和TFS Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了:

https:// github .com / libgit2 / libgit2sharp



据我所知,TFS 2015中使用的git客户端。我试图运行测试:

  public void CanCloneFromBBWithCredentials(string url,string user,string pass,bool secure)

在:

https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp.Tests/CloneFixture.cs



我在哪里更新过使用Git仓库,我在TFS中:

  [理论] 
//[InlineData(\"https://libgit2@bitbucket.org/libgit2/testgitrepository.git,libgit3,libgit3,true)]

[InlineData( http:// tfs / tfs / collection / project / _git / MyRepo,myUser,myPass,false)]
// [InlineData(http:/ / tfs / tfs / collection / project / _git / MyRepo,myUser,myPass,true)]
$ b $ public void CanCloneFromBBWithCredentials(string url,string user,string pass,bool secure)
{
var scd = BuildSelfCleaningDirectory();

字符串clonedRepoPath = Repository.Clone(url,scd.DirectoryPath,new CloneOptions()
{
CredentialsProvider =(_url,_user,_cred)=> CreateUsernamePasswordCredentials(user,通过,安全)
});

使用(var repo = new Repository(clonedRepoPath))

我运行测试我得到以下异常:

 在LibGit2Sharp.Core.Ensure.HandleError(Int32 result)in c:\\ \\ tmp\Repos\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:行160 
在LibGit2Sharp.Core.Ensure.ZeroResult(Int32结果)在c:\ tmp \Repos\libgit2sharp \LibGit2Sharp\Core\Ensure.cs:第178行b $ b在LibGit2Sharp.Core.Proxy.git_clone(String url,String workdir,GitCloneOptions& opts)in c:\ tmp\Repos\libgit2sharp\\ \\ LibGit2Sharp \Core\Proxy.cs:line 328
at LibGit2Sharp.Repository.Clone(String sourceUrl,String workdirPath,CloneOptions options)in c:\ tmp\Repos\libgit2sharp\LibGit2Sharp\ Repository.cs:第694行
at LibGit2Sharp.Tests.CloneFixture.CanCloneFromBBWithCredentials(String url,String user,String pass,Bool ean secure)in c:\ tmp\Repos\libgit2sharp\LibGit2Sharp.Tests\CloneFixture.cs:line 227

我已验证可以使用上面提供的用户名和密码从命令行使用以下命令克隆存储库: https://git-scm.com/



有关如何针对TFS 2015 Git存储库运行libgit2sharp测试的任何想法?

解决方案

DefaultCredentials type是TFS git协议不依赖于用户名和密码进行身份验证。



正如 xml文档 ,它是将通过凭证对象提供默认凭据(登录用户信息) NTLM或SPNEGO认证。



CloneOptions.CredentialsProvider 设置为以下内容应该可以做到这一点

  CredentialsProvider =(_url,_user,_cred)=>新的DefaultCredentials()


I have cloned:

https://github.com/libgit2/libgit2sharp

which as I understand is the git client used in TFS 2015. I am trying to run the test:

   public void CanCloneFromBBWithCredentials(string url, string user, string pass, bool secure)

In:

https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp.Tests/CloneFixture.cs

Where I have updated it to use a Git repository I have in TFS:

    [Theory]
    //[InlineData("https://libgit2@bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3", true)]

    [InlineData("http://tfs/tfs/collection/project/_git/MyRepo", "myUser", "myPass", false)]
   // [InlineData("http://tfs/tfs/collection/project/_git/MyRepo", "myUser", "myPass", true)]

        public void CanCloneFromBBWithCredentials(string url, string user, string pass, bool secure)
        {
            var scd = BuildSelfCleaningDirectory();

            string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
            {
                CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials (user, pass, secure)
            });

            using (var repo = new Repository(clonedRepoPath))

But when I run the test I get the following exception:

   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\tmp\Repos\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 160
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in c:\tmp\Repos\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 178
   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in c:\tmp\Repos\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 328
   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in c:\tmp\Repos\libgit2sharp\LibGit2Sharp\Repository.cs:line 694
   at LibGit2Sharp.Tests.CloneFixture.CanCloneFromBBWithCredentials(String url, String user, String pass, Boolean secure) in c:\tmp\Repos\libgit2sharp\LibGit2Sharp.Tests\CloneFixture.cs:line 227

I have verified that I can use the userName and password provided above to clone the repository from command line using: https://git-scm.com/

Any ideas on how to run libgit2sharp tests against a TFS 2015 Git repository?

解决方案

DefaultCredentials type is what you're after as TFS git protocol doesn't rely on username and password for authentication.

As stated by the xml documentation, it's "A credential object that will provide the "default" credentials (logged-in user information) via NTLM or SPNEGO authentication."

Settings the CloneOptions.CredentialsProvider to the following should do the trick

CredentialsProvider = (_url, _user, _cred) => new DefaultCredentials()

这篇关于LibGit2Sharp和TFS Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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