LibGit2Sharp: Fetching fails with "Too many redirects or authentication replays"

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.