|
1 |
| -## About |
| 1 | +# Check |
2 | 2 |
|
| 3 | +## About |
3 | 4 | This feature checks whether the commit message follows the given committing rules.
|
| 5 | +If you want to setup an automatic check before every git commit, please refer to |
| 6 | +[Automatically check message before commit](auto_check.md) |
4 | 7 |
|
5 |
| -## Checking before the commit |
6 |
| -To automatically check a commit message prior to committing, you can use a [git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). There are two common methods for installing the hook: |
7 |
| - |
8 |
| -### Method 1: Add git hook through [pre-commit](https://pre-commit.com/) |
9 |
| - |
10 |
| -* Step 1: Install [pre-commit](https://pre-commit.com/) |
11 |
| - |
12 |
| -```sh |
13 |
| -python -m pip install pre-commit |
14 |
| -``` |
15 |
| - |
16 |
| -* Step 2: Create `.pre-commit-config.yaml` at your root directory with the following content |
| 8 | +## Usage |
| 9 | +There are three arguments that you can use one of them to check commit message |
17 | 10 |
|
18 |
| -```yaml |
19 |
| ---- |
20 |
| -repos: |
21 |
| - - repo: https://github.com/commitizen-tools/commitizen |
22 |
| - rev: v1.17.0 |
23 |
| - hooks: |
24 |
| - - id: commitizen |
25 |
| - stages: [commit-msg] |
| 11 | +### Commit Message File |
| 12 | +```bash |
| 13 | +$ cz check --commit-msg-file COMMIT_MSG_FILE |
26 | 14 | ```
|
| 15 | +In this option, COMMIT_MSG_FILE is the path of the temporal file that contains the commit message |
27 | 16 |
|
28 |
| -* Step 3: Install the configuration into git hook through `pre-commit` |
29 |
| - |
| 17 | +### Git Rev Range |
| 18 | +If you'd like to check a commit's message after it has already been created, then you can specify the range of commits to check with `--rev-range REV_RANGE` |
30 | 19 | ```bash
|
31 |
| -pre-commit install --hook-type commit-msg |
| 20 | +$ cz check --rev-range REV_RANGE |
32 | 21 | ```
|
| 22 | +For example, if you'd like to check all commits on a branch, you can use `--rev-range master..HEAD`. Or, if you'd like to check all commits starting from when you first implemented commit message linting, you can use `--rev-range <first_commit_sha>..HEAD`. |
33 | 23 |
|
34 |
| -### Method 2: Manually add git hook |
35 |
| -The command might be included inside of a Git hook (inside of `.git/hooks/` at the root of the project). |
36 |
| - |
37 |
| -The selected hook might be the file called commit-msg. |
38 |
| - |
39 |
| -This example shows how to use the check command inside of commit-msg. |
40 |
| - |
41 |
| -At the root of the project: |
| 24 | +For more info on how git commit ranges work, you can check the [git documentation](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_commit_ranges). |
42 | 25 |
|
| 26 | +### Commit Message |
| 27 | +There are two ways you can provide your plain message and check it |
| 28 | +#### Method 1: use -m or --message |
43 | 29 | ```bash
|
44 |
| -cd .git/hooks |
45 |
| -touch commit-msg |
46 |
| -chmod +x commit-msg |
| 30 | +$ cz check --message MESSAGE |
47 | 31 | ```
|
| 32 | +In this option, MESSAGE is the commit message to be checked |
48 | 33 |
|
49 |
| -Open the file and edit it: |
50 |
| - |
51 |
| -```sh |
52 |
| -#!/bin/bash |
53 |
| -MSG_FILE=$1 |
54 |
| -cz check --commit-msg-file $MSG_FILE |
| 34 | +#### Method 2: use pipe to pipe it to `cz check` |
| 35 | +```bash |
| 36 | +$ echo MESSAGE | cz check |
55 | 37 | ```
|
56 |
| - |
57 |
| -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. |
58 |
| - |
59 |
| -The `--commit-msg-file` flag is required, not optional. |
60 |
| - |
61 |
| -Each time you create a commit, automatically, this hook will analyze it. |
62 |
| -If the commit message is invalid, it'll be rejected. |
63 |
| - |
64 |
| -The commit should follow the given committing rules; otherwise, it won't be accepted. |
65 |
| - |
66 |
| -## Checking after the commit |
67 |
| -If you'd like to check a commit's message after it has already been created, then you can specify the range of commits to check with `--rev-range REV_RANGE` |
68 |
| - |
69 |
| -For example, if you'd like to check all commits on a branch, you can use `--rev-range master..HEAD`. Or, if you'd like to check all commits starting from when you first implemented commit message linting, you can use `--rev-range <first_commit_sha>..HEAD`. |
70 |
| - |
71 |
| -For more info on how git commit ranges work, you can check the [git documentation](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_commit_ranges). |
| 38 | +In this option, MESSAGE is piped to cz check and would be checked |
0 commit comments