diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e54255193f..d0765d5b75 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,6 @@ repos: rev: v2.31.0 # automatically updated by Commitizen hooks: - id: commitizen - stages: [commit-msg] - repo: local hooks: diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index b32bc56e36..619e58622b 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,9 +1,27 @@ - id: commitizen name: commitizen check - description: "Check whether the commit message follows commiting rules" + description: > + Check whether the current commit message follows commiting rules. Allow + empty commit messages by default, because they typically indicate to Git + that the commit should be aborted. entry: cz check args: [--allow-abort, --commit-msg-file] stages: [commit-msg] language: python language_version: python3 minimum_pre_commit_version: "1.4.3" + +- id: commitizen-branch + name: commitizen check branch + description: > + Check all commit messages that are already on the current branch but not the + default branch on the origin repository. Useful for checking messages after + the fact (e.g., pre-push or in CI) without an expensive check of the entire + repository history. + entry: cz check + args: [--rev-range, origin/HEAD..HEAD] + always_run: true + pass_filenames: false + language: python + language_version: python3 + minimum_pre_commit_version: "1.4.3" diff --git a/docs/README.md b/docs/README.md index 9a99d11fd1..555d32377c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -101,7 +101,7 @@ cz commit -s ``` ### Integrating with Pre-commit -Commitizen can lint your commit message for you with `cz check`. +Commitizen can lint your commit messages for you with `cz check`. You can integrate this in your [pre-commit](https://pre-commit.com/) config with: ```yaml @@ -111,14 +111,23 @@ repos: rev: master hooks: - id: commitizen + - id: commitizen-branch + stages: [push] ``` -After the configuration is added, you'll need to run +After the configuration is added, you'll need to run: ```sh -pre-commit install --hook-type commit-msg +pre-commit install --hook-type commit-msg pre-push ``` +If you aren't using both hooks, you needn't install both stages. + +| Hook | Recommended Stage | +| ----------------- | ----------------- | +| commitizen | commit-msg | +| commitizen-branch | pre-push | + Read more about the `check` command [here](check.md). ### Help