-
-
Notifications
You must be signed in to change notification settings - Fork 18
Description
While commitlint is by default a primary a hook designed to work on commit-msg stage, there are some real benefits on having it also work with pre-commit stage.
Reasoning
Lots of pre-commit (tool) users are not using git hooks at all, they just run the tool locally and on CI/CD (GitHub, gitlab, jenkins,...) too. Implementing a different CI specific pipeline for verifying if the last commit was ok requires considerable time and does not address the local running issue.
If we would have a hook version designed to check the last commit and that runs in the pre-commit stage, it will enable pre-commit tool users to add commitlint hook without having to do other actions (or install hooks).
This is also more desirable a git commit --amend is bypassing pre-commit hooks unless -m is mentions, basically when run interactively we cannot benefit from the commit-mgs hook.
Few hours later... after tinkering with various approaches to make it also usable with pre-commit default stage, I produced:
# this runs commitlint (also works with shallow clones)
sh -c "if [ ! -f .git/COMMIT_EDITMSG ]; then git show -s --format=%s > .git/COMMIT_EDITMSG; fi && pre-commit run --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG commitlint"
# this runs the other pre-commit hooks
pre-commit run --all-files --show-diff-on-failureObviously that what we see above is not nice and I would not want to have to copy/paste it into all places where I use pre-commit tool. Now, if we can make this part of current hooks we have the issue sorted. I should mention that you cannot really make the default commitlint hook work with both cases.
I am aware about the secondary travis hook, which had something in common with this one: the need to run commitlint after the commit was already made. Maybe we could generalize this into a single hook that can be used both locally and on CI too. @alessandrojcm would you support such direction?