-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Some projects maintainers require that all linters must be installed via pre-commit
ant its YAML configuration, even when they are called from a CI.
Typically they want to use a tox profile simply calling " pre-commit run --all-files --show-diff-on-failure".
This is not possible with gitlint since it only proposes a pre-commit configuration
for the commit-msg stage with different defaults than the one recommended in
a CI, mainly because a .git/COMMIT_EDITMSG file is needed.
When running pre-commit in a CI system the COMMIT_EDITMSG does not
(normally) get created as that is an artifact of editing the commit
message. If the file does not exist then gitlint will skip which makes
it possible for pre-commit checks that should fail, to pass.
A workaround is proposed by the global-jjb project at
https://gerrit.linuxfoundation.org/infra/c/releng/global-jjb/+/67641
to generate such a file but it had several drawbacks such as:
- the necessity to pass the HOME variable to virtualenv even locally
- /bin/sh as whitelist_externals
- conditional scripting that might have unexpected side-effects in
another situation.
Indeed, the issue should better be fixed in gitlint uptream repository
itself so that gitlint can be run at the commit stage from pre-commit.
Since gitlint embeds its own hook solution for this stage, this
configuration is not (yet?) proposed in gitlint official repository.
https://jorisroovers.com/gitlint/#using-gitlint-through-pre-commit
Also the pre-commit hook provided up to now has a different behavior
than standalone gitlint defauts settings that are advised in a CI
context (i.e. "gitlint lint" or simply "gitlint").
https://jorisroovers.com/gitlint/#using-gitlint-in-a-ci-environment
The parameters --stage and --msg-filename options are passed and they
appear to be the root cause of the problems in the CI since they add
new requirements i.e. a local git user configuration and the presence of
an extra file argument.
https://github.com/guillaumelambert/gitlint/blob/main/.pre-commit-hooks.yaml
introduced in commit 9de1f89
pre-commit hook YAML upstream configuration does not allow to use
different options depending on the stage inside a same id block nor with
two blocks using the same id.
Only options from the last block appears to be used in that case.
As a consequence, a new id "gitlint0" must be declared but it still can
use the same name "gilint" displayed at runtime.