Closed Wirone closed 1 year ago
I started implementing this with something like this:
diff --git a/src/Hook/Template/Local/Shell.php b/src/Hook/Template/Local/Shell.php
index 006002e4..d7ce30fb 100644
--- a/src/Hook/Template/Local/Shell.php
+++ b/src/Hook/Template/Local/Shell.php
@@ -91,11 +91,15 @@ class Shell extends Template\Local
$useTTY,
[
'',
- $executable
+ 'if [ -f "' . $executable . '" ] ; then',
+ ' ' . $executable
. ' $INTERACTIVE'
. ' --configuration=' . $this->configPath
. ' --bootstrap=' . $this->bootstrap
. ' hook:' . $hook . ' "$@"' . $useStdIn,
+ 'else',
+ ' echo "Captain Hook is not installed, run \`composer install\`!";',
+ 'fi',
]
);
}
But it handles only scenario with missing vendor/bin/captainhook
. The second one is harder, I don't actually know where I should hook into π
If they delete the vendor folder they can also remove the hook scripts.
My advice, use the PHAR version install it with phive
and keep your dev tooling out of Composer :)
Yes, they can, but I'm talking about people not necessarily knowing about tooling behind the process. In such cases those people are clueless, they get error and ask about it on Slack π. I believe it could be supported, but understand if you don't want it (but then it shouldn't be closed as "completed" π).
There is some edge case scenario, that happens sometimes in our organisation:
vendor/bin/captainhook
is created,vendor/captainhook/captainhook
is available, everything works in Gitvendor
There is error:
.git/hooks/pre-commit: line 7: vendor/bin/captainhook: No such file or directory
which prevents commitIn our case it happens because we have huge monolith app and some people does not work with PHP there, sometimes people just want to fix some texts without building whole app. The problem is that sometimes they trigger Captain Hook's scripts installation (we have it on
post-autoload-dump
) and then for some reason removevendor
dir. In the end they have invalid environment, with Git hooks installed, andvendor/bin/captainhook
called, which fails. It leads to problems because often people do not know how to fix it which causes unneeded discussions.It would be great if Captain Hook was fail-safe and transparent from developer's point of view. Each script or wrapper should not prevent from using Git when CH installation is broken.
PS. similar scenario is when
vendor
dir is present,vendor/bin/captainhook
is present, but onlyvendor/captainhook/captainhook
is missing for some reason: