Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 159f6ba

Browse files
committed
docs(cz_check): the 'check' document is refactored and the usage of read commit message from pipe is added
1 parent fb03666 commit 159f6ba

File tree

2 files changed

+91
-50
lines changed

2 files changed

+91
-50
lines changed

‎docs/auto_check.md‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Automatically check message before commit
2+
3+
## About
4+
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).
5+
6+
## How to
7+
There are two common methods for installing the hook:
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
17+
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]
26+
```
27+
28+
* Step 3: Install the configuration into git hook through `pre-commit`
29+
30+
```bash
31+
pre-commit install --hook-type commit-msg
32+
```
33+
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:
42+
43+
```bash
44+
cd .git/hooks
45+
touch commit-msg
46+
chmod +x commit-msg
47+
```
48+
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
55+
```
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+

‎docs/check.md‎

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,47 @@
1-
## About
1+
#Check
22

3+
## About
34
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).
47

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/)
8+
## Usage
9+
There are three arguments that you can use one of them to check commit message.
910

10-
* Step 1: Install [pre-commit](https://pre-commit.com/)
11+
### Git Rev Range
12+
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`.
1113

12-
```sh
13-
python -m pip install pre-commit
14+
```bash
15+
$ cz check --rev-range REV_RANGE
1416
```
1517

16-
* Step 2: Create `.pre-commit-config.yaml` at your root directory with the following content
18+
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`.
1719

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]
26-
```
20+
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).
2721

28-
* Step 3: Install the configuration into git hook through `pre-commit`
22+
### Commit Message
23+
There are two ways you can provide your plain message and check it.
24+
#### Method 1: use -m or --message
2925

3026
```bash
31-
pre-commit install --hook-type commit-msg
27+
$ cz check --message MESSAGE
3228
```
3329

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.
30+
In this option, MESSAGE is the commit message to be checked.
3831

39-
This example shows how to use the check command inside of commit-msg.
40-
41-
At the root of the project:
32+
#### Method 2: use pipe to pipe it to `cz check`
4233

4334
```bash
44-
cd .git/hooks
45-
touch commit-msg
46-
chmod +x commit-msg
35+
$ echo MESSAGE | cz check
4736
```
4837

49-
Open the file and edit it:
38+
In this option, MESSAGE is piped to cz check and would be checked.
5039

51-
```sh
52-
#!/bin/bash
53-
MSG_FILE=1ドル
54-
cz check --commit-msg-file $MSG_FILE
55-
```
40+
### Commit Message File
5641

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`.
42+
```bash
43+
$ cz check --commit-msg-file COMMIT_MSG_FILE
44+
```
7045

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).
46+
In this option, COMMIT_MSG_FILE is the path of the temporal file that contains the commit message.
47+
This argument can be useful when cooperating with git hook, please check [Automatically check message before commit](auto_check.md) for more information about how to use this argument with git hook.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /