Reputation: 182
I've got a problem while trying to fetch from my repository using libgit2sharp.
I'm trying to fetch from my Github repository. It is cloned via https. As soon as the fetch command runs, the LibGit2SharpException throws saying: "too many redirects or authentication replays".
I've read a few other questions here on so, but none of them helped so far. Using DefaultCredentials
only leads to a 401 error, which makes sense.
Does anybody know how to solve this one?
using Repository repo = new Repository(@"path\to\repo");
Remote remote = repo.Network.Remotes["origin"];
IEnumerable<string> refSpec = remote.FetchRefSpecs.Select(x => x.Specification);
Credentials credentials = new UsernamePasswordCredentials { Username = "USER", Password = "PASS" };
Credentials Handler(string url, string fromUrl, SupportedCredentialTypes types) => credentials;
FetchOptions options = new FetchOptions { CredentialsProvider = Handler };
string log = "Fetching remote";
Commands.Fetch(repo, remote.Name, refSpec, options, log);
Edit: As far as I figured out, the problem is, that it's a private repo, since I can fetch public ones from github. Any ideas on how to solve it?
Upvotes: 2
Views: 892
Reputation: 182
I solved this issue with using a PersonalAccessToken from Github. The Token then can be used as the password of the credentials
Upvotes: 1