-
-
Notifications
You must be signed in to change notification settings - Fork 312
feat(prek): supporting prek as an alternative to pre-commit and switching to prek #1799
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
Open
YazdanRa
wants to merge
10
commits into
commitizen-tools:master
Choose a base branch
from
YazdanRa:feat/support-prek
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−34
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d6ae4d
feat(prek): support 'prek' as an alternative to 'pre-commit' in proje…
YazdanRa 919bf52
build(prek): replace 'pre-commit' with 'prek' in project configuration
YazdanRa 2218990
docs(auto_check): update installation instructions to include 'prek' …
YazdanRa 1b7e649
test: brought back the `pre-commit` tests along with `prek`
YazdanRa 62ca841
docs(README): update badge to reflect support for 'prek' instead of '…
YazdanRa 97fbae5
refactor(project_info): enhance pre-commit check to support multiple …
YazdanRa 331adff
docs(auto_check): update auto check installation by only keeping one …
YazdanRa 86f91fc
docs: update documentation to reflect 'prek' integration and improve …
YazdanRa a321da7
docs(auto_check): add tip for using pre-commit framework alongside prek
YazdanRa 8486876
docs: improve formatting and clarity for rendering
YazdanRa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,35 @@ | |
|
|
||
| ## About | ||
|
|
||
| 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). This ensures that all commit messages follow your project's commitizen format before they are accepted into the repository. | ||
| To automatically check a commit message before committing, use a [Git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). This ensures all commit messages match your project's commitizen format before they are accepted into the repository. | ||
|
|
||
| When a commit message fails validation, Git will reject the commit and display an error message explaining what went wrong. You'll need to amend your commit message to follow the required format before the commit can proceed. | ||
| When a commit message fails validation, Git rejects the commit and displays an error explaining what went wrong. Update the message to the required format before trying again. | ||
|
|
||
| ## How to | ||
|
|
||
| There are two common methods for installing the hooks: | ||
|
|
||
| ### Method 1: Using [pre-commit](https://pre-commit.com/) (Recommended) | ||
| ### Method 1: Using pre-commit hook frameworks (Recommended) | ||
|
|
||
| [pre-commit](https://pre-commit.com/) is a framework for managing and maintaining multi-language pre-commit hooks. It's the recommended approach as it handles hook installation, updates, and execution automatically. | ||
| Using pre-commit hook frameworks is the recommended approach because hook installation, updates, and execution are handled automatically. | ||
| Two common frameworks are: | ||
|
|
||
| #### Step 1: Install pre-commit | ||
| 1. [prek](https://prek.j178.dev) (faster) | ||
| 2. [pre-commit](https://pre-commit.com/) | ||
|
|
||
|
|
||
| In the steps below, we'll use `prek`. | ||
|
|
||
|
|
||
| !!! tip "Using pre-commit framework" | ||
| Replace `prek` with `pre-commit` in the steps below if you prefer that tool. The configuration format is similar. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand why this appears here 🤔 Might need some reworkding |
||
|
|
||
|
|
||
|
|
||
| #### Step 1: Install prek | ||
|
|
||
| ```sh | ||
| python -m pip install pre-commit | ||
| python -m pip install prek | ||
| ``` | ||
|
|
||
| #### Step 2: Create `.pre-commit-config.yaml` | ||
|
|
@@ -42,14 +55,14 @@ repos: | |
| Install the configuration into Git's hook system: | ||
|
|
||
| ```bash | ||
| pre-commit install --hook-type commit-msg | ||
| prek install --hook-type commit-msg | ||
| ``` | ||
|
|
||
| The hook is now active! Every time you create a commit, commitizen will automatically validate your commit message. | ||
|
|
||
| ### Method 2: Manual Git hook installation | ||
bearomorphism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| If you prefer not to use pre-commit, you can manually create a Git hook. This gives you full control over the hook script but requires manual maintenance. | ||
| If you prefer not to use a pre-commit framework, you can manually create a Git hook. This gives you full control over the hook script but requires manual maintenance. | ||
|
|
||
| #### Step 1: Create the commit-msg hook | ||
|
|
||
|
|
@@ -90,7 +103,7 @@ git commit -m "invalid commit message" | |
| git commit -m "feat: add new feature" | ||
| ``` | ||
|
|
||
| If the hook is working correctly, invalid commit messages will be rejected with an error message explaining what's wrong. | ||
| If the hook is working correctly, invalid commit messages are rejected with an error explaining what's wrong. | ||
|
|
||
| ## What happens when validation fails? | ||
|
|
||
|
|
@@ -123,12 +136,12 @@ pattern: ^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\)) | |
| - **Verify commitizen is installed**: Run `cz --version` to confirm commitizen is available in your PATH | ||
| - **Check Git version**: Ensure you're using a recent version of Git that supports hooks | ||
|
|
||
| ### Pre-commit hook not working | ||
| ### Prek hook not working | ||
|
|
||
| - **Verify installation**: Run `pre-commit --version` to confirm pre-commit is installed | ||
| - **Reinstall the hook**: Try running `pre-commit install --hook-type commit-msg` again | ||
| - **Verify installation**: Run `prek --version` to confirm pre-commit is installed | ||
| - **Reinstall the hook**: Try running `prek install --hook-type commit-msg` again | ||
| - **Check configuration**: Verify your `.pre-commit-config.yaml` file is valid YAML and in the project root | ||
| - **Update hooks**: Run `pre-commit autoupdate` to update to the latest versions | ||
| - **Update hooks**: Run `prek autoupdate` to update to the latest versions | ||
|
|
||
| ### Bypassing the hook (when needed) | ||
|
|
||
|
|
@@ -145,4 +158,5 @@ git commit --no-verify -m "your message" | |
|
|
||
| - Learn more about [Git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) | ||
| - See the [check command documentation](../commands/check.md) for more validation options | ||
| - Check out [prek documentation](https://prek.j178.dev/) for advanced hook management | ||
| - Check out [pre-commit documentation](https://pre-commit.com/) for advanced hook management | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.