How to use libgit2sharp with ssh-transport-protocol?

一世执手 提交于 2019-11-29 07:02:28

Unfortunately, Ssh protocol is not supported yet. At this time only git:// (read-only) and http[s]:// protocols are.

However, it will eventually be, by leveraging the libssh2 library.

Subscribing to issue #255 notifications will keep you updated about the progress made regarding this feature.

Update:

There's a work in progress in libgit2 (see PR #2428) that should help us make LibGit2Sharp able to cope with the ssh protocol sooner rather than later.

Update 2:

PR #852 is working on making ssh available to LibGit2Sharp

Unfortunately, LibGit2Sharp does not include necessary crypto libraries out of box (https://github.com/libgit2/libgit2sharp/issues/255#issuecomment-212580185).

Use LibGit2Sharp-SSH NuGet package (fork).

private void Run()
{
    var url = "ssh://username@gitblit.example.com/some/repository.git";
    var path = @"C:\Temp\some-repository";

    LibGit2Sharp.Repository.Clone(url, path, new LibGit2Sharp.CloneOptions { CredentialsProvider = MyCredentialsProvider });
}

private Credentials MyCredentialsProvider(string url, string usernameFromUrl, SupportedCredentialTypes types)
{
    var sshDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh");

    return new LibGit2Sharp.SshUserKeyCredentials()
    {
        Username = usernameFromUrl,
        Passphrase = string.Empty,
        PublicKey = Path.Combine(sshDir, "id_rsa.pub"),
        PrivateKey = Path.Combine(sshDir, "id_rsa"),
    };
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!