Description
The hook scripts generated by CaptainHook unconditionally call vendor/bin/captainhook without checking that the binary exists. This causes git worktree add to fail, because the post-checkout hook fires in the new worktree before composer install has been run.
Steps to reproduce
- Have a project with CaptainHook installed and hooks active (including
post-checkout)
- Run
git worktree add /tmp/my-worktree HEAD
Expected behavior
The worktree is created successfully. The hook either skips execution or exits gracefully when vendor/bin/captainhook is not available.
Actual behavior
The hook fails with:
Preparing worktree (new branch 'worktree-xxx')
.git/hooks/post-checkout: 17: vendor/bin/captainhook: not found
The worktree creation is aborted.
Root cause
The generated hook template calls vendor/bin/captainhook unconditionally:
vendor/bin/captainhook $INTERACTIVE --configuration=captainhook.json --input="$input" hook:post-checkout "$@"
In a fresh worktree, vendor/ does not exist yet — composer install has not run.
Suggested fix
Guard the invocation with an existence check:
[ -x vendor/bin/captainhook ] && vendor/bin/captainhook $INTERACTIVE --configuration=captainhook.json --input="$input" hook:post-checkout "$@"
This affects all generated hooks, not just post-checkout, since any hook could theoretically fire in a context where vendor/ is absent (e.g., sparse checkouts, CI environments that install hooks before dependencies).
Environment
- CaptainHook 5.25.11
- Git 2.49.0
- PHP 8.5.0
Description
The hook scripts generated by CaptainHook unconditionally call
vendor/bin/captainhookwithout checking that the binary exists. This causesgit worktree addto fail, because thepost-checkouthook fires in the new worktree beforecomposer installhas been run.Steps to reproduce
post-checkout)git worktree add /tmp/my-worktree HEADExpected behavior
The worktree is created successfully. The hook either skips execution or exits gracefully when
vendor/bin/captainhookis not available.Actual behavior
The hook fails with:
The worktree creation is aborted.
Root cause
The generated hook template calls
vendor/bin/captainhookunconditionally:In a fresh worktree,
vendor/does not exist yet —composer installhas not run.Suggested fix
Guard the invocation with an existence check:
This affects all generated hooks, not just
post-checkout, since any hook could theoretically fire in a context wherevendor/is absent (e.g., sparse checkouts, CI environments that install hooks before dependencies).Environment