I am using libgit2sharp to on a proof of concept to automate fetching, changing, commiting some files, and pushing to a remote origin.
I know that push is still not finished yet, but fetch is in vnext but when I call it:
An error was raised by libgit2. Category = Os (Error).
Failed to connect to host
Here is my code:
using (var repo = new Repository(gitPath))
{
var allBranches = repo.Branches.ToList(); //works fine
var creds = new Credentials() {Username = username, Password = password};
var remote = repo.Remotes.FirstOrDefault(x => x.Name == "origin");
remote.Fetch(credentials:creds); //blows up here
}
Some other details:
- My remote is private bitbucket hosted using https. (looks like: https://myusername@bitbucket.org/myRepoOwner/repoName.git)
- I am able to fetch and push from the command line, so the repo is working.
- The same issue happens when I use repo.Fetch(“origin”);
This sounds like an issue that was recently fixed in
libgit2(and likely has not yet been integrated intolibgit2sharp.)In the mean time, you should be able to remove the
myusername@from your remote URI to work around this problem, eghttps://bitbucket.org/myRepoOwner/repoName.git.