Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: project scope .husky/init.sh #1533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/es/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ echo "npm test" > .husky/pre-commit

Husky le permite ejecutar comandos locales antes de ejecutar ganchos (hooks). Husky lee comandos de estos archivos:

- `.husky/init.sh`
- `$XDG_CONFIG_HOME/husky/init.sh`
- `~/.config/husky/init.sh`
- `~/.huskyrc` (obsoleto (deprecated))
Expand Down
1 change: 1 addition & 0 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ echo "npm test" > .husky/pre-commit

Husky allows you to execute local commands before running hooks. It reads commands from these files:

- `.husky/init.sh`
- `$XDG_CONFIG_HOME/husky/init.sh`
- `~/.config/husky/init.sh`
- `~/.huskyrc` (deprecated)
Expand Down
1 change: 1 addition & 0 deletions docs/ru/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ echo "npm test" > .husky/pre-commit

Husky позволяет выполнять локальные команды перед запуском хуков. Он считывает команды из следующих файлов:

- `.husky/init.sh`
- `$XDG_CONFIG_HOME/husky/init.sh`
- `~/.config/husky/init.sh`
- `~/.huskyrc` (устарело)
Expand Down
1 change: 1 addition & 0 deletions docs/zh/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ echo "npm test" > .husky/pre-commit

Husky 允许你在运行钩子之前执行本地命令。它从这些文件中读取命令:

- `.husky/init.sh`
- `$XDG_CONFIG_HOME/husky/init.sh`
- `~/.config/husky/init.sh`
- `~/.huskyrc` (已弃用)
Expand Down
3 changes: 3 additions & 0 deletions husky
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n

i="${s%/*}/init.sh"
[ -f "$i" ] && . "$i"

[ ! -f "$s" ] && exit 0

if [ -f "$HOME/.huskyrc" ]; then
Expand Down
3 changes: 2 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ sh test/8_set_u.sh
sh test/9_husky_0.sh
sh test/10_init.sh
sh test/11_time.sh
sh test/12_deprecated.sh
sh test/12_deprecated.sh
sh test/13_project_scope_init.sh
14 changes: 14 additions & 0 deletions test/13_project_scope_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
. test/functions.sh
setup
install

npx --no-install husky

git add package.json
cat >.husky/init.sh <<'EOL'
#!/usr/bin/env sh
exit 1
EOL

expect 1 "git commit -m foo"