How to use libgit2sharp with ssh-transport-protoco

2019-01-25 12:46发布

When I use libgit2sharp in project to clone repository with ssh-transport protocol, like

git@github.com:libgit2/libgit2sharp.git 

It throw an exception, says "This transport isn't implemented. Sorry"

How can I clone repository with ssh-transport-protocol by using libgit2sharp ?

2条回答
Fickle 薄情
2楼-- · 2019-01-25 13:21

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

查看更多
该账号已被封号
3楼-- · 2019-01-25 13:22

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"),
    };
}
查看更多
登录 后发表回答