How to use libgit2sharp with ssh-transport-protocol?
Asked Answered
S

2

9

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 ?

Subreption answered 16/6, 2014 at 7:59 Comment(0)
G
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

Gasper answered 16/6, 2014 at 11:36 Comment(7)
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?Carlist
Not yet. But LibGit2Sharp will eventually allow this feature.Gasper
Looks like there is some progress on libgit2 on this github.com/libgit2/libgit2/pull/2600Zucker
@RichardMitchell Subscribing to github.com/libgit2/libgit2sharp/pull/852 would also be a good idea ;-)Gasper
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?Oleg
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.Kreager
Can we get an Update 3? Tried following the trail but after 10 minutes still haven't found current statusCotswold
L
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://[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"),
    };
}
Linkoski answered 18/6, 2017 at 15:11 Comment(5)
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?Somatotype
I don't know about LibGit2Sharp internals, but you may try to manually parse .ssh\config file. cyberciti.biz/faq/create-ssh-config-file-on-linux-unixLinkoski
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???Pharyngitis
btw, this is a non-working code example, making use of variables that are not defined anywhere in your code sample.Adage
Which variables are not defined?Linkoski

© 2022 - 2024 — McMap. All rights reserved.