gitbutler icon indicating copy to clipboard operation
gitbutler copied to clipboard

feat: allow signing rebased commits

Open Pranav2612000 opened this issue 1 year ago • 2 comments

Not sure if this is the best way to do it. Especially, setting rebase_options.inmemory(false); to false. If not, I'll try to make it work by adding git_commit_create_cb support to git2

Fixes #3147

cc: @schacon @krlvi

Pranav2612000 avatar Mar 20 '24 14:03 Pranav2612000

I don't believe that this will work. If rebase is not in in_memory mode, it will try messing with the HEAD and working directory, which is going to put the project in a weird state most likely.

I think what's probably much simpler would be to do exactly what we're doing, but at the end, if the rebase is successful, simply rewrite all the rebased commits, reuse the trees and manually write the commits with the signature.

So, basically, here: https://github.com/gitbutlerapp/gitbutler/blob/a1e2b92abcbfecf038f8b00c2ca25512731fcb0b/gitbutler-app/src/virtual_branches/virtual.rs#L1557

If there is a signing key, instead of just saving the rebased head here, we should calculate the list of commits from the base (merge_base) to that head (last_rebase_head), then walk through them starting from the first child of the base and for each one, rerun project_repository.commit() with the user, message and tree from that commit, and the parent that was written last. (does that make sense?)

schacon avatar Mar 20 '24 14:03 schacon

Thanks for contributing!

Since the PR was created, a lot has changed which puts it into a conflicting stage unfortunately. Also I hope you will find time to try out the suggestions.

If that's not the case, please feel free to close it and resubmit when that changes.

Thank you.

Byron avatar Apr 25 '24 13:04 Byron

Hey @Pranav2612000, I just refactored how commits are done in general in a way that should sign everything properly now. The change is in #3721. I'll close this, since it's out of date and based on code that has been pretty massively changed and now should address this.

schacon avatar May 15 '24 12:05 schacon

Sure. Thank you @schacon Sorry for not replying earlier.

I think the cleanest way to do this would be to use the git_commit_create_cb method of libgit2. Since git2rs does not yet have support for it, I've opened up a PR [ https://github.com/rust-lang/git2-rs/pull/1047 ] to add this support and was waiting for this to be merged.

I'll open up this conversation again once the method is available in libgit2 and we can then decided if we want to use it or not. Does that work?

Pranav2612000 avatar May 17 '24 11:05 Pranav2612000