libgit2/libgit2sharp

LibGit2Sharp.LibGit2SharpException:“too many redirects or authentication replays”

Hdurian-CH opened this issue · 0 comments

I get LibGit2Sharp.LibGit2SharpException:“too many redirects or authentication replays” when I push the repository.
I use username&&password in CredentialsProvider

using var repo = new Repository(rootPath);
var options = new PushOptions
{
    CredentialsProvider = (url, user, cred) =>
        new UsernamePasswordCredentials { Username = userName, Password = password },
};

var remoteName = "origin";
var remote = repo.Network.Remotes.FirstOrDefault(r => r.Name == remoteName);
 if (remote == null)
{
     repo.Network.Remotes.Add(remoteName, res);
}

 var branch = repo.Branches["main"];
if (branch == null)
 {
     branch = repo.CreateBranch("main");
 }
repo.Branches.Update(branch, b => b.Remote = remoteName, b => b.UpstreamBranch = branch.CanonicalName);
repo.Network.Push(branch, options);