Skip to content

Commit 487b3e2

Browse files
committed
change: update output message for help command (works with "git worktree")
- docs: updated README file - usage, tip for git alias
1 parent 9563b43 commit 487b3e2

File tree

6 files changed

+52
-24
lines changed

6 files changed

+52
-24
lines changed

README.md

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,77 +10,103 @@
1010
The Conventional Precommit Linter is a tool designed to ensure commit messages follow the Conventional Commits standard, enhancing the readability and traceability of your project's history.
1111
<hr>
1212

13-
14-
## Table of Contents
15-
16-
- [Table of Contents](#table-of-contents)
17-
- [Getting Started](#getting-started)
13+
- [Usage](#usage)
1814
- [Commit Message Structure](#commit-message-structure)
19-
- [Installation](#installation)
15+
- [Setup](#setup)
2016
- [Install Commit-msg Hooks](#install-commit-msg-hooks)
21-
- [Configuration](#configuration)
17+
- [Configuration](#configuration)
2218
- [Project issues](#project-issues)
2319
- [Contributing](#contributing)
2420
- [Credits](#credits)
2521

2622
---
2723

28-
## Getting Started
24+
## Usage
25+
26+
The _conventional-precommit-linter hook_ runs every time you execute the `git commit` command (when you want to commit your changes). Since this hook operates in the `commit-msg` stage, simply running a pre-commit check without actually committing (using `pre-commit run`), will have no effect, and this hook will be ignored.
27+
28+
The same applies to running pre-commit hooks in CI (Continuous Integration) job environments - **this hook is simply skipped when you run pre-commit checks in your CI system**.
2929

3030
### Commit Message Structure
31+
3132
Commit messages are validated against the following format:
33+
3234
```
3335
<type>(<optional-scope>): <summary>
3436
< ... empty line ... >
3537
<optional body lines>
3638
<optional body lines>
3739
<optional body lines>
3840
```
41+
3942
Each component is checked for compliance with the provided or default configuration.
4043

41-
**Example output for failed message:**
44+
If your commit message does not meet the required format, the hook will fail, producing a **report that shows which part of your commit message needs correction**:
45+
4246
<img src="docs/example-output-default-args.jpg" width="800">
4347

44-
**Example output for failed message (with custom arguments):**
45-
<img src="docs/example-output-custom-args.jpg" width="710">
48+
For a custom configuration, the report might look like this:
49+
<img src="docs/example-output-custom-args.jpg" width="800">
4650

47-
### Installation
51+
The hint message suggests that you can preserve your original message and simply edit it in your default editor, without the need to type the whole message again.
52+
53+
To edit failed message, run the command (as the hint suggests):
54+
55+
```sh
56+
git commit --edit --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG
57+
```
58+
59+
Since this command is quite complex and you may use this functionality often, **creating a Git alias might be a good idea**:
60+
61+
```sh
62+
git config --global alias.again '!git commit --edit --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG'
63+
```
64+
65+
This command adds a `git again` alias to your machine's Git configuration. You can run then simply `git again` whenever your commit message check fails.
66+
67+
---
68+
69+
## Setup
4870

4971
To integrate the **Conventional Precommit Linter** into your project, add to your `.pre-commit-config.yaml`:
5072

5173
```yaml
5274
# FILE: .pre-commit-config.yaml
5375
repos:
5476
- repo: https://github.com/espressif/conventional-precommit-linter
55-
rev: v1.3.0 # The version tag you wish to use
77+
rev: v1.7.0 # The version tag you wish to use
5678
hooks:
5779
- id: conventional-precommit-linter
5880
stages: [commit-msg]
5981
```
6082
6183
### Install Commit-msg Hooks
84+
6285
**IMPORTANT:** `commit-msg` hooks require a specific installation command:
86+
6387
```sh
6488
pre-commit install -t pre-commit -t commit-msg
6589
```
6690

6791
**Note:** The `pre-commit install` command by default sets up only the `pre-commit` stage hooks. The additional flag `-t commit-msg` is necessary to set up `commit-msg` stage hooks.
6892

6993
For a simplified setup (just with `pre-commit install` without flags), ensure your `.pre-commit-config.yaml` contains the following:
94+
7095
```yaml
7196
# FILE: .pre-commit-config.yaml
7297
---
7398
minimum_pre_commit_version: 3.3.0
74-
default_install_hook_types: [pre-commit,commit-msg]
75-
...
99+
default_install_hook_types: [pre-commit, commit-msg]
76100
```
101+
77102
After modifying `.pre-commit-config.yaml`, re-run the installation command (`pre-commit install`) for changes to take effect.
78103

79-
---
104+
-
80105

81-
## Configuration
106+
### Configuration
82107

83108
The linter accepts several configurable parameters to tailor commit message validation:
109+
84110
- `--types`: Define the types of commits allowed (default: [`change`, `ci`, `docs`, `feat`, `fix`, `refactor`, `remove`, `revert`, `test`]).
85111
- `--scopes`: Specifies a list of allowed scopes. If not defined, all scopes are allowed (restriction is `disabled`).
86112
- `--subject-min-length`: Set the minimum length for the summary (default: `20`).
@@ -90,16 +116,17 @@ The linter accepts several configurable parameters to tailor commit message vali
90116
- `--allow-breaking`: Allow exclamation mark in the commit type (default: `false`).
91117

92118
The **custom configuration** can be specified in `.pre-commit-config.yaml` like this:
119+
93120
```yaml
94121
# FILE: .pre-commit-config.yaml
95-
...
122+
---
96123
- repo: https://github.com/espressif/conventional-precommit-linter
97-
rev: v1.3.0 # The version tag you wish to use
124+
rev: v1.7.0 # The version tag you wish to use
98125
hooks:
99126
- id: conventional-precommit-linter
100127
stages: [commit-msg]
101128
args:
102-
- --types=change,ci,docs,feat,fix,refactor,remove,revert,fox
129+
- --types=build,ci,docs,feat,fix,perf,refactor,style,test # default Angular / @commitlint-conventional types
103130
- --scopes=bt,wifi,ethernet
104131
- --subject-min-length=10
105132
```
@@ -119,4 +146,5 @@ If you encounter any issues, feel free to report them in the [project's issues](
119146
---
120147

121148
## Credits
149+
122150
Inspired by project: https://github.com/compilerla/conventional-pre-commit

conventional_precommit_linter/hook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def print_report(commit_type: str, commit_scope: Optional[str], commit_summary:
208208
"""
209209
print(full_guide_message)
210210
print(
211-
f'👉 To preserve and correct a commit message, run: {_color_bold_green("git commit --edit --file=.git/COMMIT_EDITMSG")}'
211+
f'👉 To preserve and correct a commit message, run: {_color_bold_green("git commit --edit --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG")}\n'
212212
)
213213

214214

@@ -247,7 +247,7 @@ def main(argv: Optional[List[str]] = None) -> int:
247247
if not check_colon_after_type(message_title):
248248
print(f'❌ Missing colon after {_color_purple("<type>")} or {_color_blue("(<optional-scope>)")}.')
249249
print(
250-
f'\nEnsure the commit message has the format \"{_color_purple("<type>")}{_color_blue("(<optional-scope>)")}: {_color_orange("<summary>")}\"'
250+
f'\nEnsure the commit message has the format "{_color_purple("<type>")}{_color_blue("(<optional-scope>)")}: {_color_orange("<summary>")}"'
251251
)
252252
return 1
253253

docs/example-output-custom-args.jpg

2.9 KB
Loading

docs/example-output-default-args.jpg

14.1 KB
Loading

tests/test_custom_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def commit_message_id(commit_message): # pylint: disable=redefined-outer-name
5757
),
5858
(
5959
# Expected PASS: Message without scope, with body
60-
'change: This is commit message without scope with body\n\nThis is a text of body\n# Please enter the commit message for your changes. Lines starting\n# with \'#\' will be ignored, and an empty message aborts the commit.\n#',
60+
"change: This is commit message without scope with body\n\nThis is a text of body\n# Please enter the commit message for your changes. Lines starting\n# with '#' will be ignored, and an empty message aborts the commit.\n#",
6161
{},
6262
),
6363
(

tests/test_default_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def commit_message_id(commit_message): # pylint: disable=redefined-outer-name
5656
),
5757
(
5858
# Expected PASS: Message without scope, with body
59-
'change: This is commit message without scope with body\n\nThis is a text of body\n# Please enter the commit message for your changes. Lines starting\n# with \'#\' will be ignored, and an empty message aborts the commit.\n#',
59+
"change: This is commit message without scope with body\n\nThis is a text of body\n# Please enter the commit message for your changes. Lines starting\n# with '#' will be ignored, and an empty message aborts the commit.\n#",
6060
{},
6161
),
6262
(

0 commit comments

Comments
 (0)