Search code examples
git-pulllibgit2sharp

Libgit2sharp:how to use "git pull“


using (var repo = new Repository("path/to/your/repo"))
{
    LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
    options.FetchOptions = new FetchOptions();
    options.FetchOptions.CredentialsProvider = new CredentialsHandler(
        (url, usernameFromUrl, types) =>
            new UsernamePasswordCredentials()
            {
                Username = USERNAME,
                Password = PASSWORD
            });
    repo.Network.Pull(new LibGit2Sharp.Signature(USERNAME, EMAIL, new DateTimeOffset(DateTime.Now)), options)
}

i do not konw how to set arguments,when i use it,one error will show-----Unsupported URL protocol.could you tell me how to set arguments?


Solution

  • It depends on the url you are using.

    For instance, issue 649 clearly states:

    git.git supports relative URLs in remote configurations and resolves them relative to the working directory.
    libgit2 currently fails with "Unsupported URL protocol".

    It expects paths to be absolute.

    So if your url is actually a local path, make sure it is an absolute path (and not a relative one).

    As commented by 崔重阳, using an https instea of an sssh url is supported.