1
votes

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:

  1. My remote is private bitbucket hosted using https. (looks like: https://[email protected]/myRepoOwner/repoName.git)
  2. I am able to fetch and push from the command line, so the repo is working.
  3. The same issue happens when I use repo.Fetch("origin");
1

1 Answers

3
votes

This sounds like an issue that was recently fixed in libgit2 (and likely has not yet been integrated into libgit2sharp.)

In the mean time, you should be able to remove the myusername@ from your remote URI to work around this problem, eg https://bitbucket.org/myRepoOwner/repoName.git.