Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use libgit2sharp with ssh-transport-protocol?

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

[email protected]: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 ?

like image 338
hutusi Avatar asked Jun 16 '14 07:06

hutusi


2 Answers

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

like image 97
nulltoken Avatar answered Oct 27 '22 07:10

nulltoken


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://[email protected]/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"),
    };
}
like image 34
Der_Meister Avatar answered Oct 27 '22 07:10

Der_Meister