lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Enable rebasing and patching of commits even when using GPG

Open felixschndr opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Lazygit does not allow rebasing of commits when the user uses GPG to sign his commits. There is a check in the source code (https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/rebase.go#L402) that prevents the user from doing a rebase (and thus any other function that needs rebasing such as rewording).

Describe the solution you'd like The source code states

	// we can make this GPG thing possible it just means we need to do this in two parts:
	// one where we handle the possibility of a credential request, and the other
	// where we continue the rebase

It'd be great if the behaviour could be implemented as signing commits is (IMHO) an important part of git, especially when committing to larger open source repos.

Additional context Signing commits does work. Rebasing and patching (https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/patch.go#L153) does not. To be honest I don't see why not (I guess I don't understand the workflow). However as I see it: When the user wants his commits to be signed the only thing that has to be changed is to add a -S to the commands. git itself will take care of the rest.

felixschndr avatar Jul 18 '24 08:07 felixschndr

the only thing that has to be changed is to add a -S to the commands.

That's only true if your signing uses some sort of password agent so that no password needs to be typed (in other words, if your git.overrideGpg config is true). If not, lazygit needs to suspend itself to the background at the appropriate times so that you get a chance to type the password; as I understand it, that's the part that makes this tricky.

(I may be wrong though, maybe it's easier than I thought.)

stefanhaller avatar Jul 18 '24 08:07 stefanhaller

That's only true if your signing uses some sort of password agent so that no password needs to be typed (in other words, if your git.overrideGpg config is true). If not, lazygit needs to suspend itself to the background at the appropriate times so that you get a chance to type the password; as I understand it, that's the part that makes this tricky.

That's probably true. I forgot about this since I don't have a pw on my GPG key and thus don't have to type anything...^^

felixschndr avatar Jul 20 '24 10:07 felixschndr

for me when i try rebase and my gpg signature password was typed in recently, all works as expected. When not it goes to some broken state where its stuck in "Rebasing..." and whole UI flickers. So basically my flow when rebasing needs to start outside lazygit

git rebase main

first and then open lazygit and it works as expected. This should probably be just a bug because apart from rebasing, this "lazygit pausing to ask for password" works pretty flawlessly when you commit.

viktor21minds avatar Dec 02 '24 12:12 viktor21minds

Btw: I built a version of lazygit which removes the checks from the code. For users with GPG without a passphrase this works flawlessly and thus removes the restrictions to not be able to patch and rebase. You can find it here. It updates automatically whenever there is a new release of the upstream lazygit.

felixschndr avatar Dec 02 '24 14:12 felixschndr

Perhaps there could be a config option to disable this behaviour, with the default being that it's enabled? That way, people without signature passwords, or who are using a password agent that handles it for them, could use this feature.

At the very least, it should give the error message as soon as I hit the "reword" key, rather than letting me update the commit message and only then telling me it's not going to accept it and my only option is to lose the changes I've just made!

@felixschndr Thanks for the patched release — would you be willing to create a Homebrew formula for it?

unikitty37 avatar Jan 21 '25 11:01 unikitty37

Perhaps there could be a config option to disable this behaviour, with the default being that it's enabled? That way, people without signature passwords, or who are using a password agent that handles it for them, could use this feature.

There is, it's called git.overrideGpg. From reading the code, it sounds like it should work in this case too (haven't tried). Let me know if that doesn't solve it.

stefanhaller avatar Jan 21 '25 12:01 stefanhaller

There is, it's called git.overrideGpg. From reading the code, it sounds like it should work in this case too (haven't tried). Let me know if that doesn't solve it.

I don't think (haven't tested) that git.overrideGpg will help as the code from lazygit refuses to call git in the first place. What @unikitty37 means (I think) and would appreciate as well is an option to disable the if clause in https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/rebase.go#L416 and https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/patch.go#L153


Thanks for the patched release — would you be willing to create a Homebrew formula for it?

Yes, I will do that. I recently switched to Mac so I have this usecase myself. I just haven't come around to do it yet. Since I don't have any experience with creating a programm for homebrew I'll have to see how that works. I got exam phase at university at the moment, will take a look at this afterwards (≈3 weeks)

felixschndr avatar Jan 21 '25 13:01 felixschndr

There is, it's called git.overrideGpg. From reading the code, it sounds like it should work in this case too (haven't tried). Let me know if that doesn't solve it.

I don't think (haven't tested) that git.overrideGpg will help as the code from lazygit refuses to call git in the first place. What @unikitty37 means (I think) and would appreciate as well is an option to disable the if clause in https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/rebase.go#L416 and https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/git_commands/patch.go#L153

Yes, the UsingGpg function does that, if you look at its implementation. It will return false if the git.overrideGpg is true. Please test this.

stefanhaller avatar Jan 21 '25 13:01 stefanhaller

Yes, the UsingGpg function does that, if you look at its implementation. It will return false if the git.overrideGpg is true. Please test this.

I am so sorry, I thought you were talking about a setting of git itself and not lazygit.

Yes git.overrideGpg works as exactly as I need it and makes my repo redundant. @unikitty37 Does this satisfy your needs as well?

felixschndr avatar Jan 21 '25 13:01 felixschndr

Thanks @felixschndr — git.overrideGpg does indeed do the right thing: I can reword commits without getting an error.

In fact, when I tried it, 1Password popped up to request I unlock it so it could authenticate my SSH key that I'm signing with, and lazygit waited patiently for it without a problem :)

unikitty37 avatar Jan 21 '25 13:01 unikitty37

Then I will close this issue and add a comment to my integration that is is unnecessary

felixschndr avatar Jan 21 '25 19:01 felixschndr