jesseduffield / lazygit

simple terminal UI for git commands
MIT License
53.41k stars 1.86k forks source link

Allow precommit-bypassing fixup! commit #2275

Open amunrarara opened 2 years ago

amunrarara commented 2 years ago

Is your feature request related to a problem? Please describe. It's not a problem, but it's very frustrating when I want to add a fixup! commit and I have to run my entire precommit hook, or disable it manually and re-enable it afterward.

Describe the solution you'd like I'd like to see a fixup! commit command that bypasses pre-commit hooks.

Describe alternatives you've considered

koliyo commented 1 month ago

Same here, I have a branch prefix hook based on issue id, and I do not want to run this hook when doing fixup/rewrite actions

stefanhaller commented 1 month ago

We already have the skipHookPrefix config that can be used for this. By default it is set to "WIP", but you can set it to "fixup!" like this:

git:
  skipHookPrefix: "fixup!"

The problem is that we only allow a single prefix, so if you want all of "WIP", "fixup!", "squash!", and "amend!", then this can't be done currently.

One way to solve this could be to turn the config into an array that's called skipHookPrefixes.

koliyo commented 1 month ago

Oh, nice, thanks ❤️ This is probably enough for me, but I can see that supporting multiple prefixes would be even better.

koliyo commented 1 month ago

I did actually try this now but I am unable to make it work. The prepare-commit-msg still run and prefix the fixup message.

I have this config:

git:
  skipHookPrefix: fixup!

gui:
  theme:
    activeBorderColor:
      - blue

And the border is blue, so I know the config is loaded

It does not matter If i commit manually with a fixup! ... message, or if I use the fixup command, the prepare-commit-msg prefix is still applied

stefanhaller commented 1 month ago

Ah, if this is about prepare-commit-msg, then the skipHookPrefix config doesn't help for that. All it does is pass --no-verify to the git commit call, and that bypasses the pre-commit hook (which is what this issue was originally about), but not prepare-commit-msg.

A quick google search shows that git has no way to do that; there are workarounds, but they require you to modify the hook. Here's one way.

koliyo commented 1 month ago

Ok, thanks for explanation and pointer to workaround.

I have not however been able to successfully use the skipHookPrefix setting. Using lg -debug and lg -logs I can trace the commands, and the git commit --fixup does not contain --no-verify.

However, the workaround you pointed to works really good if I modify it to not check for --no-verify, but instead check for --fixup directly. This means I do not depend on the lazygit config anymore. So this is actually even better for me and will work with all --fixup commands from any git tool.

if ps -o args= $PPID | grep -E -q ' --fixup| -n | -n$' ; then
  exit
fi