Repository navigation
What is the correct way to run shell scripts in a hook in v9? #1543
|
In v8 etc we could put anything in the hook file eg. #!/bin/sh
. "$(dirname "$0")/_/husky.sh"
echo "Doing step 1 of pre-commit hook"
npx ....
echo "Doing step 2 of pre-commit hook"
npx ...What's the correct way to achieve this in v9? If i remove the shebang header and #!/bin/sh
echo "Doing step 1 of pre-commit hook"
npx ....
echo "Doing step 2 of pre-commit hook"
npx ...However, if I remove the |
Replies: 1 comment
|
Hi @janeklb In Husky v9, hooks are plain POSIX shell scripts — no shebang or sourcing needed. What changed in v9The No shebang requiredIn v9, Husky executes hooks directly. The shebang and the sourcing line from v8 are no longer needed. If you need Bash featuresIf your hook requires Bash-specific syntax, use this pattern: TestingAfter editing, test with: The |
Hi @janeklb
In Husky v9, hooks are plain POSIX shell scripts — no shebang or sourcing needed.
What changed in v9
The
.husky/_directory is a Husky internal directory. You don't need to source it. Hook scripts are simple shell commands:No shebang required
In v9, Husky executes hooks directly. The shebang and the sourcing line from v8 are no longer needed.
If you need Bash features
If your hook requires Bash-specific syntax, use this pattern:
Testing
After editing, test with:
git commit --allow-empty -m "test hook"The
exit 1trick sti…