Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch/pull using SSH #2135

Closed
marcelovbcfilho opened this issue Dec 24, 2024 · 10 comments
Closed

How to fetch/pull using SSH #2135

marcelovbcfilho opened this issue Dec 24, 2024 · 10 comments

Comments

@marcelovbcfilho
Copy link

marcelovbcfilho commented Dec 24, 2024

You are opening a bug report against the LibGit2Sharp project: we
use GitHub Issues for tracking bug reports and feature requests. If
you have a question about an API or usage, please ask on StackOverflow:
http://stackoverflow.com/questions/tagged/libgit2sharp.

Otherwise, to report a bug, please fill out the reproduction steps
(below) and delete these introductory paragraphs. Thanks!

Reproduction steps

Create a project and try and fetch/pull using the OS configured SSH.
I tried asking it on stack overflow, but let's say that they were not very receptive with my question, so here I am.
image

Expected behavior

Have some sort of documentation or sample teaching how to use the OS ssh key to make execute certain operations. When I look at the fetch/pull wiki(last update 2018) there is no mention on how to use the SSH, since github and some other platforms don't accept the old username and password authentication this should be more easy to access.

https://github.com/libgit2/libgit2sharp/wiki/git-pull
https://github.com/libgit2/libgit2sharp/wiki/git-fetch

Actual behavior

Version of LibGit2Sharp (release number or SHA1)

0.31.0

Operating system(s) tested; .NET runtime tested

Windows, .NET 9

@bording
Copy link
Member

bording commented Dec 24, 2024

I'm not really sure what you're looking for here. There's nothing special that LibGit2Sharp requires to use SSH.

If your command-line git client works with SSH, then so should LibGit2Sharp.

If you need guidance on how to do that, you should check out https://docs.github.com/en/authentication/connecting-to-github-with-ssh

@marcelovbcfilho
Copy link
Author

Hmm, but all the example on the wiki require a username and password to make the fetch/pull actions and I would like to avoid needing to use the username and password, maybe I'm just not knowing how to use the lib.

@bording
Copy link
Member

bording commented Dec 24, 2024

Hmm, but all the example on the wiki require a username and password to make the fetch/pull actions and I would like to avoid needing to use the username and password, maybe I'm just not knowing how to use the lib.

As I said before, there's literally nothing special to do:

Repository.Clone("[email protected]:libgit2/libgit2sharp.git", @"f:\repo");

If you already have your SSH keys set up, it just works.

@marcelovbcfilho
Copy link
Author

marcelovbcfilho commented Dec 24, 2024

Hmm, but what about the pull and fetch operation that according to the wiki would require a username and password?
The sample there is this:

using (var repo = new Repository("path/to/your/repo"))
{
    // Credential information to fetch
    LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
    options.FetchOptions = new FetchOptions();
    options.FetchOptions.CredentialsProvider = new CredentialsHandler(
        (url, usernameFromUrl, types) =>
            new UsernamePasswordCredentials()
            {
                Username = USERNAME,
                Password = PASSWORD
            });

    // User information to create a merge commit
    var signature = new LibGit2Sharp.Signature(
        new Identity("MERGE_USER_NAME", "MERGE_USER_EMAIL"), DateTimeOffset.Now);

    // Pull
    Commands.Pull(repo, signature, options);
}

or I can just ignore the credential provider? And pass an "empty" fetchOption? I was assuming that everything in the sample was mandatory.

@bording
Copy link
Member

bording commented Dec 24, 2024

You don't have to specify credentials.

@marcelovbcfilho
Copy link
Author

marcelovbcfilho commented Dec 24, 2024

Hey, thanks for the help, it worked. Out of my curiosity, when I execute the pull command a terminal flashes for a second, is there a way to prevent it from appearing? Or is this a side effect of how the Commands work under the hood?

@bording
Copy link
Member

bording commented Dec 24, 2024

What sort of application are you using LibGit2Sharp from?

@marcelovbcfilho
Copy link
Author

I'm using it from a Godot application, but the issue appears to be exclusive to Widows, the terminal that appears seems to be related with OpenSSH. When I run the app and do the same Commands.Pull but on Linux the terminal window does not flashes.

Image 1: Print of the terminal window title that flashes
Screenshot 2024-12-24 094411

@ethomson
Copy link
Member

Good question. I think that you could rebuild libgit2 with libssh2, but that's a parcel of other problems that you would have to deal with.

I can investigate the windows side. There are various exec options and some of them open windows, so we might be able to suppress it. But we'd really need to know that it shouldn't prompt for a key phrase. (It's also possible that something in the openssh realm is opening the window, not us.) 😵‍💫

I can investigate a bit on the

@marcelovbcfilho
Copy link
Author

Hey thanks for the help, I was just curious about the terminal flashing, but it is not a deal breaker for me. I will close the issue because the original problem already has been solved.
Thanks a lot for the help everyone 😁.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants