From 1188920658d667f264a7def62d1a59993e04ecbb Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 15 May 2022 23:49:43 -0400 Subject: [PATCH 1/4] fix(pre-commit): Don't require serial execution require_serial is not pertinent to commit-msg hooks or hooks that themselves execute serially. The option is intended to prevent fork-bombing that can occur when pre-commit runs a hook that itself spawns many processes many times in parallel. --- .pre-commit-hooks.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 956f15250e..0083d2c06b 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -4,5 +4,4 @@ entry: cz check --commit-msg-file language: python language_version: python3 - require_serial: true minimum_pre_commit_version: "0.15.4" From ddfb7734c6f530d587aff2bbba736e1f620150ba Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 15 May 2022 23:54:49 -0400 Subject: [PATCH 2/4] fix(pre-commit): Set min pre-commit to v1.4.3 pre-commit 1.4.3, released 2018-01-02, is the minimum pre-commit version at which language_version: python3 is translated to the correct py launcher call on Windows. --- .pre-commit-hooks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 0083d2c06b..b41944cde0 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -4,4 +4,4 @@ entry: cz check --commit-msg-file language: python language_version: python3 - minimum_pre_commit_version: "0.15.4" + minimum_pre_commit_version: "1.4.3" From 76d784b51fa37c0fd929016738ad6e96b3920d8d Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 15 May 2022 23:18:59 -0400 Subject: [PATCH 3/4] fix(pre-commit): Confine hook to commit-msg stage The Commitizen pre-commit hook runs cz check, which only makes sense to do on a commit message, not at other Git hook stages. By default the hook is currently run on staged files pre-commit, which is nonsensical unless the files in the repository themselves contain Git commit messages. The hook is an implausible candidate even for the prepare-commit-msg stage since this stage is intended for hooks that modify the commit message rather than check it. Specifying the hook stage centrally makes it less error-prone to use and saves one line of configuration for users of the pre-commit hook. --- .pre-commit-hooks.yaml | 1 + commitizen/commands/init.py | 2 +- docs/README.md | 1 - docs/auto_check.md | 1 - tests/commands/test_init_command.py | 2 +- 5 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index b41944cde0..2eccdce347 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -2,6 +2,7 @@ name: commitizen check description: "Check whether the commit message follows commiting rules" entry: cz check --commit-msg-file + stages: [commit-msg] language: python language_version: python3 minimum_pre_commit_version: "1.4.3" diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index d290612949..73d76e9022 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -114,7 +114,7 @@ def _install_pre_commit_hook(self): cz_hook_config = { "repo": "https://github.com/commitizen-tools/commitizen", "rev": f"v{__version__}", - "hooks": [{"id": "commitizen", "stages": ["commit-msg"]}], + "hooks": [{"id": "commitizen"}], } config_data = {} diff --git a/docs/README.md b/docs/README.md index f459ccfa28..9a99d11fd1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -111,7 +111,6 @@ repos: rev: master hooks: - id: commitizen - stages: [commit-msg] ``` After the configuration is added, you'll need to run diff --git a/docs/auto_check.md b/docs/auto_check.md index 755f1af8b7..d0437bc7b6 100644 --- a/docs/auto_check.md +++ b/docs/auto_check.md @@ -22,7 +22,6 @@ repos: rev: v1.17.0 hooks: - id: commitizen - stages: [commit-msg] ``` * Step 3: Install the configuration into git hook through `pre-commit` diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index e7f2c00edf..131aaaad44 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -21,7 +21,7 @@ def ask(self): cz_hook_config = { "repo": "https://github.com/commitizen-tools/commitizen", "rev": f"v{__version__}", - "hooks": [{"id": "commitizen", "stages": ["commit-msg"]}], + "hooks": [{"id": "commitizen"}], } expected_config = ( From 522509e637136a9a30a48277c16705126e7a319d Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 15 May 2022 20:03:13 -0700 Subject: [PATCH 4/4] fix(pre-commit): Use new --allow-abort option Prevent pre-commit hook from complaining when a commit is aborted by default, but allow users to override this option in their pre-commit config by specifying it in args, not entry. Move --commit-msg-file option from entry to args since it has to be the last option. --- .pre-commit-hooks.yaml | 3 ++- docs/auto_check.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 2eccdce347..b32bc56e36 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,8 @@ - id: commitizen name: commitizen check description: "Check whether the commit message follows commiting rules" - entry: cz check --commit-msg-file + entry: cz check + args: [--allow-abort, --commit-msg-file] stages: [commit-msg] language: python language_version: python3 diff --git a/docs/auto_check.md b/docs/auto_check.md index d0437bc7b6..fc76bdf88b 100644 --- a/docs/auto_check.md +++ b/docs/auto_check.md @@ -50,7 +50,7 @@ Open the file and edit it: ```sh #!/bin/bash MSG_FILE=$1 -cz check --commit-msg-file $MSG_FILE +cz check --allow-abort --commit-msg-file $MSG_FILE ``` Where `$1` is the name of the temporary file that contains the current commit message. To be more explicit, the previous variable is stored in another variable called `$MSG_FILE`, for didactic purposes.