LibGit2Sharp: Fetching fails with “Too many redirects or authentication replays”

不羁岁月 提交于 2019-11-28 13:01:38

I tried @Carlos' suggestion in the following way:

public static void GitFetch()
{
    var creds = new UsernamePasswordCredentials()
                {Username = "user",
                 Password = "pass"};
    CredentialsHandler credHandler = (_url, _user, _cred) => creds;
    var fetchOpts = new FetchOptions { CredentialsProvider = credHandler };
    using (repo = new Repository(@"C:\project");)
    {
        repo.Network.Fetch(repo.Network.Remotes["origin"], fetchOpts);
    }
}

I could fetch from public repos on github as well as from password protected private repos on bitbucket; however, I couldn't do the same for the repositories hosted over LAN at work. Turns out they were configured in a way which does not accept UsernamePasswordCredentials provided by libgit2sharp. The following modification allowed me to fetch from repositories over LAN:

    CredentialsHandler credHandler = (_url, _user, _cred) => new DefaultCredentials();

(I'm trying to find out what is the exact difference between the two; if I get further insight into it, I'll update the answer.)

The shim that should make the Credentials option work is currently buggy (and is deprecated anyway), pass a CredentialsProvider instead as a callback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!