9

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 ?

hutusi
  • 437
  • 6
  • 14

2 Answers2

8

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

Community
  • 1
  • 1
nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • Thanks for this answer! So now there is no way to clone/push a git repository with ssh keys using LibGit2Sharp in a C# appliation? – Gábor Domonkos Jul 31 '14 at 09:02
  • 1
    Not yet. But LibGit2Sharp will eventually allow this feature. – nulltoken Aug 24 '14 at 17:40
  • Looks like there is some progress on libgit2 on this https://github.com/libgit2/libgit2/pull/2600 – Richard Mitchell Nov 18 '14 at 09:14
  • @RichardMitchell Subscribing to https://github.com/libgit2/libgit2sharp/pull/852 would also be a good idea ;-) – nulltoken Nov 18 '14 at 10:49
  • Out of general interest, when this comes in, will Visual Studio automatically get this support? Is the (awesome) Git support in VS connected to this or another dependency? – Luke Puplett Nov 21 '14 at 17:04
  • 1
    If / when this lands in LibGit2Sharp it will *not* automatically get included in Visual Studio. Sorry. We have a policy to not ship cryptosystems or software that implements them (like libssh2) without review. – Edward Thomson Nov 21 '14 at 19:22
  • 3
    Can we get an Update 3? Tried following the trail but after 10 minutes still haven't found current status – Kyle Gobel Jun 27 '16 at 17:28
4

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"),
    };
}
Der_Meister
  • 4,771
  • 2
  • 46
  • 53
  • From this sample it looks like you can't make its SSH implementation look up the user keys automatically, and have to guess whatever paths they might be at — manually in your code. Which is non-trivial. Is the piece for keys selection from `%USERPROFILE%\.ssh` totally missing from libssh2? Or is it possible to turn it on? – hypersw Jan 25 '18 at 19:15
  • I don't know about LibGit2Sharp internals, but you may try to manually parse .ssh\config file. https://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/ – Der_Meister Jan 26 '18 at 05:41
  • My code throws a protcol error before it ever even reaches the credentials provider, so it can't be a key issue. Apparently, libssh2 had a flaw and now this library cannot connect to any patched servers??? – Triynko Nov 20 '18 at 04:52
  • btw, this is a non-working code example, making use of variables that are not defined anywhere in your code sample. – C.J. Oct 02 '19 at 16:16
  • Which variables are not defined? – Der_Meister Oct 02 '19 at 18:03