LibGit2Sharp: Fetch occurs with the error "Too many redirects or retries of authentication"

Here is the code I use to extract:

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

but it does not work during sampling with the following exception:

LibGit2Sharp.LibGit2SharpException: Too many redirects or authentication replays
Result StackTrace:  
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
   at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
   at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage)

I checked that the configuration file has the required remote name and that git fetch works from the command line. I found that this exception comes from libgit2\src\transport\winhttp.c, but I could not come up with a workaround / solution.

0
source share
2 answers

I tried the @Carlos suggestion as follows:

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

github, bitbucket; , . , , UsernamePasswordCredentials, libgit2sharp. :

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

( , , , .)

+4

, Credentials, ( ), CredentialsProvider .

+2

All Articles