如何在Fetch调用期间提供凭据?

时间:2013-02-06 06:34:38

标签: libgit2sharp

我们不是在讨论SSH,因为它尚未实现,但在通过HTTP / HTTPS执行提取之前,如何为存储库提供凭据?似乎没有Credentials实例的参数,在构建存储凭证的Repository实例时没有任何参数。

1 个答案:

答案 0 :(得分:4)

FetchFixture.cs 文件中,有一个 Fetch() test using credentials

    [SkippableFact]
    public void CanFetchIntoAnEmptyRepositoryWithCredentials()
    {
        InconclusiveIf(() => string.IsNullOrEmpty(Constants.PrivateRepoUrl),
            "Populate Constants.PrivateRepo* to run this test");

        string repoPath = InitNewRepository();

        using (var repo = new Repository(repoPath))
        {
            Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);

            // Perform the actual fetch
            repo.Network.Fetch(remote, new FetchOptions
            {
                Credentials = new Credentials
                    {
                        Username = Constants.PrivateRepoUsername,
                        Password = Constants.PrivateRepoPassword
                    }
            });
        }
    }