gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Support git commit signing using OpenPGP

Open hendrikmaus opened this issue 2 years ago โ€ข 32 comments

This Pull Request fixes/closes #97.

It changes the following:

  • Add a new trait called Sign
  • Implement Sign for gpg commit signing via shellout
    • Users with a working signing setup will find that it just works in gitui as well
  • Add entrypoints for all natively supported methods
  • Add potential entrypoint for pure rust implementations behind a gitconfig value of gitui.signing_methods

I followed the checklist:

  • [x] I added unittests
  • [x] I ran make check without errors
  • [x] I tested the overall application
  • [ ] I added an appropriate item to the changelog

Todo:

  • [x] Test in Windows ๐ŸชŸ
  • [ ] Documentation
  • [ ] Draft an isolated integration test running in a container

Draft an isolated integration test running in a container

Since shellouts call out to actual system binaries, @extrawurst and I came up with the idea to create a test that runs in the isolation of a container. Inside of that environment, it could generate a GPG key and do an actual commit to verify the signature was created as expected.

hendrikmaus avatar Feb 13 '23 20:02 hendrikmaus

Will attend to the failures in CI within the next days.

hendrikmaus avatar Feb 14 '23 20:02 hendrikmaus

waiting for this feature ready

ZCShou avatar Feb 20 '23 01:02 ZCShou

Looking into the CI errors again now.

hendrikmaus avatar Feb 20 '23 07:02 hendrikmaus

๐Ÿ†— โœ… The previous error was caused by a doctest I added. The other unit tests prepare their environment, the doctest does not. Since I added it as documentation only, I deactivated the doctest and the CI run in my fork was good now: https://github.com/hendrikmaus/gitui/actions/runs/4221076989

@extrawurst if you'd approve another CI run here, thanks.

hendrikmaus avatar Feb 20 '23 07:02 hendrikmaus

Hey just checking the status of this PR? I can test on macOS and windows easily if needed :)

melMass avatar Mar 14 '23 15:03 melMass

Both would be appreciated, thank you.

hendrikmaus avatar Mar 14 '23 20:03 hendrikmaus

Tested it on macOS. Authoring commits works fine, but some simple operations like amending & rewording the last commit don't work. I've created a PR with workarounds: https://github.com/hendrikmaus/gitui/pull/1.

utkarshgupta137 avatar Mar 17 '23 16:03 utkarshgupta137

๐Ÿ‘‹ hello! Any movement on this by chance? Thanks!

tmikeschu avatar Apr 25 '23 18:04 tmikeschu

๐Ÿ‘‹ hello! Any movement on this by chance? Thanks!

Iโ€˜m also waiting for this feature

ZCShou avatar Apr 26 '23 01:04 ZCShou

Havenโ€™t had time to continue, but will do so in the beginning of ~~May~~ June (sry for the delay).

Will tackle these:

  • [x] Fix amending and rewording, thanks @utkarshgupta137 for already preparing a change-set
  • [ ] Align configuration with the existing pattern (in progress)
  • [x] Test on Windows
  • [ ] Documentation
  • [ ] Integration test

hendrikmaus avatar Apr 26 '23 05:04 hendrikmaus

Hey, how's the progress on this? :)

nrabulinski avatar May 23 '23 09:05 nrabulinski

Can someone test a current build on a Windows environment? I'd appreciate that.

hendrikmaus avatar Jun 08 '23 08:06 hendrikmaus

To test this, would we need to download this PR's code, compile, and run? Or is there some auto-generated binary for testing I should download somewhere?

damccull avatar Jun 08 '23 18:06 damccull

At this point there are no pre-compiled binaries. So you have to download and compile it.

hendrikmaus avatar Jun 08 '23 19:06 hendrikmaus

I compiled it with cargo install gitui and tried to run the binary from .cargo dir but it is showing me the same error. I might be doing something wrong...

PS: I don't have experience in working with Rust.

image

SirusCodes avatar Jun 08 '23 19:06 SirusCodes

I reckon you compiled the master branch as that is the error that was shown before this initiative started. Here is the zip file of my branch on github: https://github.com/hendrikmaus/gitui/archive/refs/heads/gpg-commit-signing.zip

hendrikmaus avatar Jun 08 '23 19:06 hendrikmaus

works like a charm on ventura๐Ÿ‘Œ

just want this pr to be merged as soon as possible

image

Sped0n0ld avatar Jun 17 '23 03:06 Sped0n0ld

I compiled it with cargo install gitui and tried to run the binary from .cargo dir but it is showing me the same error. I might be doing something wrong...

PS: I don't have experience in working with Rust.

image

maybe install with command below?

cargo install --git https://github.com/hendrikmaus/gitui --branch gpg-commit-signing

Sped0n0ld avatar Jun 17 '23 03:06 Sped0n0ld

@hendrikmaus works for me on windows 11 (built with rust using MSVC toolchain, GnuPG as program for signing)

  • Password prompt appears correctly when signing is enabled by default
  • Commits are in fact signed (verified with git log --show-signature)

eclairevoyant avatar Jun 20 '23 18:06 eclairevoyant

Thank you for the feedback, that is good news.

hendrikmaus avatar Jun 20 '23 19:06 hendrikmaus

@extrawurst re configuration.

As we were talking about this the other day, did you take another look at the available approaches? I.e. .gitconfig file versus the gitui options?

hendrikmaus avatar Jun 20 '23 20:06 hendrikmaus

Well, I installed it from the git repo and it definitely tries to sign now. However, I'm using my ssh key to sign rather than a gpg key and it says that's unsupported. Would this capability be difficult to add?

damccull avatar Jun 21 '23 02:06 damccull

@damccull out of scope here, but the change-set already prepares an entry point for that in the code. There is another open issue about signing with ssh keys in https://github.com/extrawurst/gitui/issues/1149

hendrikmaus avatar Jun 21 '23 07:06 hendrikmaus

Ah, thanks.

damccull avatar Jun 21 '23 11:06 damccull

@extrawurst re configuration.

As we were talking about this the other day, did you take another look at the available approaches? I.e. .gitconfig file versus the gitui options?

I think it would be feasible to pass a new optional struct with the signing options down into the asyncgit crate from here: https://github.com/hendrikmaus/gitui/blob/24bb8ac57e2f7c8320eb4e6b75c8dc4739b6b7e0/src/components/commit.rs#L274

The asyncgit::sync::commit function has more than 40 call sites, mostly tests, that would need to be adjusted. The signatures of asyncgit::sync::reword and asyncgit::sync::amend would also be affected as they call commit.

I would propose something like Option<CommitConfig> to implement it open for extension. We might see the need to pass more configurations down to commit and I wouldn't want to limit it to only the signing options now. What do you think @extrawurst ?

hendrikmaus avatar Jun 22 '23 07:06 hendrikmaus

Any updates on this?

lretq avatar Jul 19 '23 17:07 lretq

an interesting catch: https://github.com/libgit2/libgit2/pull/6617 - seems like libgit2 starts supporting shell-out for ssh

extrawurst avatar Aug 31 '23 08:08 extrawurst

Can't wait for this, is there a workaround as of right now?

h4rldev avatar Jan 11 '24 18:01 h4rldev

Can't wait for this, is there a workaround as of right now?

My current workaround is to use gitui for all operations it can do except commit and push. I quit it, use Connor via cli, then push real quick since I'm already there.

damccull avatar Jan 11 '24 20:01 damccull

My current workaround is to use gitui for all operations it can do except commit and push. I quit it, use Connor via cli, then push real quick since I'm already there.

Ah, so what I've been doing currently, All I've really been doing is commiting which is quite easy, will probably dwelve further into gitui once it supports gpgsigning.

h4rldev avatar Jan 12 '24 00:01 h4rldev