holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.58k stars 116 forks source link

Git via `libgit2/examples/lg2.c` client #241

Open personalizedrefrigerator opened 3 years ago

personalizedrefrigerator commented 3 years ago

Summary

holzschu commented 3 years ago

So, the good news is: I've managed to compile and install this CLI client to a-Shell. The bad news is: I can't make push work:

$ lg2 push
Error pushing [-1] - remote authentication re
quired but no callback set

It must be something with the configuration but I'm stuck. The pull situation is more dire:

$ lg2 pull
Command not found: pull

Clone, add and commit were fine.

personalizedrefrigerator commented 3 years ago

Oh no! I can keep working on the Dulwich-based client.

holzschu commented 3 years ago

I think I'll get push working eventually, and it might be easier to add pull to lg2.

holzschu commented 3 years ago

I get the same error message with lg2 on Mac, so at least it's not a porting issue.

personalizedrefrigerator commented 3 years ago

I think this libgit2 pull request is relevant to getting push to work: https://github.com/libgit2/libgit2/pull/5904

holzschu commented 3 years ago

Good find!

holzschu commented 3 years ago

It works, but it asks for the SSH key or username/password at each launch. It would be good to make it read these from the config file, or at least try the default option (.ssh/id_rsa). But it works.

holzschu commented 3 years ago

Basic pull behaviour can be done with:

lg2 fetch origin
lg2 merge FETCH_HEAD
personalizedrefrigerator commented 3 years ago

least try the default option (.ssh/id_rsa). But it works.

If this is added, it would be best to check .ssh/id_ed25519 as well -- I think it is the recommended type of key pair to generate.

holzschu commented 3 years ago

You're right. From my readings, there are no ways to specify in .gitconfig the key that should be used for a specific host. One possibility is to loop over all keys in ~/Documents/.ssh, and check if one works.

personalizedrefrigerator commented 3 years ago

It looks like that might be doable here: https://github.com/libgit2/libgit2/blob/868f4bcb4d3290f4b5320f030fccdf1e7fc8ac8a/examples/common.c#L210

holzschu commented 3 years ago

Yes, that's also what I had in mind. The difficult bit (for now) is to loop over all files in the .ssh directory and extract only the pairs where both key and key.pub exist.

holzschu commented 3 years ago

Well, that was not completely satisfying. There is no easy way with libgit2 to check that a specific SSH key works with a given host, and no way specify which key is associated with which host (at least not without opening a session). I settled for adding an option in the .gitconfig file, user.identityFile. I think this is a big part of the git user experience. Paradoxically, your work on Dulwich, because it uses the ssh command directly, will rely on .ssh/config, and might be preferable for some users.

personalizedrefrigerator commented 3 years ago

I settled for adding an option in the .gitconfig file, user.identityFile.

https://github.com/holzschu/libgit2/pull/1 should also make this easier to use... Among other things, it tells users how to add the path to an .ssh key to their current repository's configuration (using lg2 config, which I don't think supports --global yet).

personalizedrefrigerator commented 3 years ago

Thank you for helping me with this!

These are the current issues I'm noticing (many of them minor/non-blocking): See https://github.com/holzschu/libgit2/issues/10

holzschu commented 3 years ago

I don't see 'lg2 branch' in build 172.

yes, there is roughly a 12 to 24 hours delay between the time I start uploading a build to Apple servers and the time it appears on TestFlight (time to upload plus time to be approved). Build 172 corresponds to the state of the repositories on Friday night European time.

personalizedrefrigerator commented 3 years ago

yes, there is roughly a 12 to 24 hours delay between the time I start uploading a build to Apple servers and the time it appears on TestFlight (time to upload plus time to be approved). Build 172 corresponds to the state of the repositories on Friday night European time.

I was basing it on the description of the build in TestFlight :). I was worried there might have been a configuration/build issue (e.g. forgot to 'git add lg2.c' after adding the branch command).

Thank you for looking into it!

holzschu commented 3 years ago

Thanks for the heads up. I realized than branch.c and reset.c were not included in the list of C files in build_lg2.sh. I have added them, the next build should have branches.

personalizedrefrigerator commented 3 years ago

I just found this (huge) PR: https://github.com/libgit2/libgit2/pull/5507

It adds a command-line git client to libgit2. From an initial look at the changes, it appears to have more features/functionality than lg2 (but I'm not sure).

Edit: Nevermind. It appears to only have two commands: clone and help (https://github.com/libgit2/libgit2/blob/05c336bad8ef017bee1094ce561a5e07f97fe8ee/src/cli/main.c).