My husky script:
"husky": {
"hooks": {
"pre-commit": "sh ./tools/githooks/pre-commit.sh"
}
}
Let's say I am doing a git commit -m "I want that text"
.
How can I access to my commit message within the shell script?
I tried to echo $HUSKY_GIT_PARAMS and $HUSKY_GIT_STDIN within the shell script but no success
Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.
Husky is a very popular (1 million downloads a month) npm package that allows custom scripts to be ran against your repository. Husky works with any project that uses a package. json file. It also works out of the box with SourceTree!
A pre-commit hook would not access the commit message, because the hook is triggered before the commit creation.
A commit-msg hook is the right hook for checking a commit message content.
And it is available with husky in 2019
"commit-msg": "echo $HUSKY_GIT_PARAMS"
Update 2020, as commented by galethil
HUSKY_GIT_PARAMS
is removed in version 5.
Instead Git parameters should be used directly in scripts (e.g.$1
)
Note, since 2019, commit c4e1ed1 (Dec. 2020, Husky v5.0.5) mentions:
Previous
HUSKY_GIT_PARAMS
environment variable is replaced by native params$1
,$2
, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With