【问题标题】:LibGit2Sharp and TFS Git repositoryLibGit2Sharp 和 TFS Git 存储库
【发布时间】:2015-11-09 15:15:58
【问题描述】:

我已经克隆了:

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

我已经更新它以使用我在 TFS 中拥有的 Git 存储库:

    [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))

但是当我运行测试时,我得到了以下异常:

   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

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

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

【问题讨论】:

    标签: git tfs libgit2sharp


    【解决方案1】:

    DefaultCredentials 类型是您所追求的,因为 TFS git 协议不依赖用户名和密码进行身份验证。

    xml documentation 所述,它是“通过 NTLM 或 SPNEGO 身份验证提供“默认”凭据(登录用户信息)的凭据对象。” em>

    CloneOptions.CredentialsProvider 设置为以下应该可以解决问题

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

    【讨论】:

      猜你喜欢
      • 2013-02-23
      • 1970-01-01
      • 2018-06-20
      • 2016-08-15
      • 1970-01-01
      • 2015-07-14
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多