lefthook
lefthook copied to clipboard
Documentation to work with commitlint?
Unfortunately the commitlint documentation only has these instructions:
{
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
And it's unclear whether lefthook exposes whatever HUSKY_GIT_PARAMS
are in such a way that it works with commitlint.
Hi @radiosilence It is impossible to store documentation for every tool in the world. Check the full guide and if you have a questions feel free to ask.
Maybe that what a you looking for? https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#bash-script-example
I use it like this:
pre-commit:
parallel: true
commands:
lint-commit:
run: npx commitlint --from HEAD~1 --to HEAD
@muuvmuuv Somehow, this doesn't work for me. I also read, that the pre-commit
hook should not work for this usecase. Apparently, the commit-msg
hook should be used instead. Though this won't work for me as well :/
@Arkweid I took a look at your example using the bash script. I'm trying to figure out how this could be used with a tool like commitlint without using a separate script file. Is there a way to access the commit message in the run command? Maybe using an environment variable or an argument?
For simple run
lefthook not pass arguments from git.
If you need just a commit message, so as a mentioned above you could use a various git commands like git show
Oh, sorry, noticed that my above does not work, but this one does:
commit-msg:
commands:
lint-commit-msg:
run: npx commitlint --edit
--edit, -e read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG
I have a similar use-case with git-notify
, where I need to pass Git parameters to post-merge
, post-rewrite
and post-checkout
hooks, with the params being dynamic — https://github.com/jevakallio/git-notify#installing-hooks-by-any-other-means
Has someone had success doing this?
EDIT: I can see in https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#git-hook-argument-shorthands-in-commands that a specific Git hook argument at position i
can be accessed with {i}
, but is there a way I can access all arguments?
@paambaati where is this related to Commitlint? Post a new issue for this please.
commit-msg: commands: lint-commit-msg: run: npx commitlint --edit
For me the above one was linting previous commit message instead of the current one. After reading lefthooks for a while I solved doing the following.
run:
lefthook add -d commit-msg
# will create .lefthook/commit-msg dir
Inside .lefthook/commit-msg
create a bash script called commit_check
and add the following.
if ! npx commitlint --edit --verbose; then
exit 1
fi
Then in lefthook.yml
add the following
commit-msg:
scripts:
'commit_check':
runner: bash
Ref: https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md#managing-scripts
I think we can close this since this guide already solved this issue.