captainhookphp / captainhook

CaptainHook is a very flexible git hook manager for software developers that makes sharing git hooks with your team a breeze.
http://captainhook.info
MIT License
992 stars 86 forks source link

Prevent captainhook running on rebase? #188

Closed dingo-d closed 1 year ago

dingo-d commented 1 year ago

Is there a way to prevent captain hook from triggering during rebase? I tried adding --no-verify but the hook is still being triggered, and then some checks may fail during the rebase and I cannot continue rebasing...

sebastianfeldmann commented 1 year ago

I most likely have to update the Cap'n to make that work. The only two solutions coming to mind right now are.

1.) Add a config setting to disable the Cap'n during rebase. But that's maybe a bit much because maybe you want to generally run it even during rebase but not for this one right now. But changing the config every time you want to do something like that doesn't make sense because you basically can do that already by disabling the hooks in the configuration.

2.) Providing a ENV-VAR that would trigger hook skipping skip-hooks=true git rebase Not sure that even works especially in interactive mode and in addition to that this poses problems if you run the Cap'n within a container or a VM.

I'm pretty sure I want my hooks to run during rebase because I still want to make sure that.

What is your problem with git hooks running during rebase?

If you have custom logic running during a hook you can detect a rebase by checking the current branch git branch and look for (no branch) and then manually skip the hook execution.

dingo-d commented 1 year ago

What is your problem with git hooks running during rebase?

One issue I ran into when I initially added the captain hook is that when interactively rebasing, and applying the commits, in the earlier commits I didn't have any config for captain hook (or captain hook lib) which threw an error that config is missing (the commit hook is registered in the .git folder once initialized and won't be rollbacked when rebasing).

I also know to push my commits while I'm working which won't pass all the status checks, because this is just WIP, and a way to 'save' my code. This is especially visible if I'm following TDD. I first write a test that fails, then write code to make it pass and then refactor. If I commit often, my commits will have failed unit tests (which will trigger captain hook). Rebasing such code (to rephrase commits, or maybe squash certain trash commits) becomes impossible.

Using Husky, I can do:

HUSKY_SKIP_HOOKS=1 HUSKY=0 git rebase -i ...

Could something like that be possible to do in captainhook?

ruscon commented 1 year ago

Have the same issue.

dingo-d commented 1 year ago

The 'dirty' workaround is to go to the .git folder, and copy the hooks folder to the desktop, or somewhere, during the rebase. Then, after you've done rebasing just return it back and re-initialize the captainhook 🤷🏼‍♂️

sebastianfeldmann commented 1 year ago

Please don't do that! The workaround is to remove the hooks in .git/hooks/* and after the rebase use captainhook install to re-create the hooks again.

sebastianfeldmann commented 1 year ago

I just released version 5.11.2 including a fix for this issue. You can now skip hook execution by running CAPTAINHOOK_SKIP_HOOKS=1 git rebase

dingo-d commented 1 year ago

Amazing! Thanks!!!