2015-11-09 60 views
0

我已經克隆:LibGit2Sharp和TFS Git倉庫

https://github.com/libgit2/libgit2sharp

這是我的理解是在2015年TFS我試圖運行測試中使用的混帳客戶端:

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

在:

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

我在哪裏公頃已經更新它使用Git倉庫我在TFS:

[Theory] 
    //[InlineData("https://[email protected]/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測試的任何想法?

回答

1

DefaultCredentials類型就是TFS git協議不依賴用戶名和密碼進行身份驗證之後的情況。

如上所述由xml documentation,它的「A憑據對象,將提供‘缺省’經由NTLM或SPNEGO的認證證書(登錄的用戶信息)」。

設置的CloneOptions.CredentialsProvider以下應該做的伎倆

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