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
1.01k stars 87 forks source link

Error 'The "--input" option does not exist' when rerunning the hooks #243

Closed alfredbez closed 5 months ago

alfredbez commented 7 months ago

I had an issue while switching branches that resulted in this message:

Composer autoloader crashed:
  Please update your autoloader by running `composer install`
  You can re-run the hook by executing `vendor/bin/captainhook --configuration=captainhook-with-pre-commit.json --bootstrap=vendor/autoload.php --input= hook:post-checkout 2285979ace8d5a69fde6c68756cac8161c9ec72c b0b2ee197acf4bcfc1e848b1546a507925e3338d 1`

I fixed the underlying issue by running composer install and wanted to rerun the hooks, so I copied the suggested command and executed:

vendor/bin/captainhook --configuration=captainhook-with-pre-commit.json --bootstrap=vendor/autoload.php --input= hook:post-checkout 2285979ace8d5a69fde6c68756cac8161c9ec72c b0b2ee197acf4bcfc1e848b1546a507925e3338d 1

This lead to this error message:

The "--input" option does not exist.

image

I changed the command then manually:

- vendor/bin/captainhook --configuration=captainhook-with-pre-commit.json --bootstrap=vendor/autoload.php --input= hook:post-checkout 2285979ace8d5a69fde6c68756cac8161c9ec72c b0b2ee197acf4bcfc1e848b1546a507925e3338d 1
+ vendor/bin/captainhook --configuration=captainhook-with-pre-commit.json --bootstrap=vendor/autoload.php hook:post-checkout 2285979ace8d5a69fde6c68756cac8161c9ec72c b0b2ee197acf4bcfc1e848b1546a507925e3338d 1

And this worked finally 🎉

Nice feature btw ❤️

sebastianfeldmann commented 7 months ago

Do your different branches depend on different captainhook versions?

One of the last updates required to re-install the hooks.

What changed: In order to allow user input for all hooks (ask the user to confirm something) I had to handle the original stdIn hook input differently. That led to a small change in the actual hook scripts. Now the stdIn is collected and passed to the Cap'n via --input option.

If your branches depend on different versions the actual hook scripts can only be valid for one version. In order to fix this you could re-install the hooks with vendor/bin/captainhook install -f --only-enabled

You could write a post-checkout hook that checks if the composer.json file changed and blindly run the install command again. Or write a custom action that checks if the Cap'n version changed. You would have to compare the composer.lock version with the composer.json version.

Again I think it is related to the incompatible hook script. This should not happen too often ... sorry :/ But even a major version update would still have the same problem, because of the version control independent hook scripts.