Skip to content

feat(pre-commit): Add commitizen-branch hook #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repos:
rev: v2.31.0 # automatically updated by Commitizen
hooks:
- id: commitizen
stages: [commit-msg]

- repo: local
hooks:
Expand Down
20 changes: 19 additions & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 12 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down