Skip to content

Commit

Permalink
fix: allow to use older pre-commit hook version
Browse files Browse the repository at this point in the history
With b93cc58 ("fix: set default pre-commit hook stages to pre-commit..")
a dependency on pre-commit 3.3 was added. As it turned out, there are
people still using e.g. 2.16 version and this change is causing problems.

1. The minimum_pre_commit_version is checked after the config is parsed.
   Meaning if there is a problem in the config file, like unknown
   pre-commit for default_stages, pre-commit exits with an error not
   suggesting that it should be updated.
2. "pre-commit" was added in 3.2 for consistency with git hook names and
   we can use "commit" instead avoiding dependency on newer pre-commit.
   For more info please see [1] and [2].
3. default_install_hook_types[4] were added in 2.18.0[3]. This was IMHO actually
   a nice feature to have in our .pre-commit-config.yaml, because it
   specifies which hooks should be installed when pre-commit install is
   executed. Meaning it's not necessary to list the stages explicitly with the -t
   options. Anyway we haven't used this feature till now, so it
   hopefully should not be a problem if we remove it again.

With this change we can still avoid to start pre-commit plugins multiple
times for different stages, but also make it compatible with older
versions(2.16).

[1] pre-commit/pre-commit#2732
[2] pre-commit/pre-commit#2808
[3] https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md#2180---2022-04-02
[4] https://pre-commit.com/#top_level-default_install_hook_types

Fixes: b93cc58 ("fix: set default pre-commit hook stages to pre-commit..")
Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
  • Loading branch information
fhrbata committed Dec 19, 2023
1 parent 3cd7fb6 commit 09ba070
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

minimum_pre_commit_version: 3.3.0
default_install_hook_types: [pre-commit, post-commit, commit-msg]
default_stages: [pre-commit]
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down

0 comments on commit 09ba070

Please sign in to comment.