【问题标题】:How can one supply credentials during a Fetch call?如何在 Fetch 调用期间提供凭据?
【发布时间】:2013-02-06 06:34:38
【问题描述】:

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

【问题讨论】:

    标签: libgit2sharp


    【解决方案1】:

    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
                        }
                });
            }
        }
    

    【讨论】:

    • 像魅力一样工作,谢谢。我还不愿意弄乱你的人的来源,所以我会提出一个问题,而不是;)
    • @JanWillemB 测试已移至 FetchFixture.cs
    • @nulltoken 谢谢,修复链接并复制测试。
    • 此 API 已过时,请使用 CredentialsProvider instead
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2018-08-22
    • 2021-05-15
    • 2010-12-27
    • 2021-07-31
    • 2017-05-21
    相关资源
    最近更新 更多