{{ message }}
fix(init): use prek when installing hooks if pre-commit is missing - #2065
Merged
woile merged 3 commits intoAug 17, 2026
Merged
Conversation
cz init already treated prek as installed, but always ran `pre-commit install`, which raised FileNotFoundError when only prek was on PATH. Use the available installer, and ask when both exist. Fixes commitizen-tools#2018
woile
reviewed
Aug 14, 2026
woile
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR, one comment only
If neither pre-commit nor prek is on PATH, skip the hook-type question instead of failing init. Users who want hooks can install a tool and retry.
The InitFailedError branch in _ask_hook_installer was flagged by codecov as the only uncovered line of the PR. Add a test where the installer is available during the hook-type question but disappears before the install step, so the guard is exercised instead of removed.
Contributor
Author
woile
approved these changes
Aug 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Description
cz initalready treatedprekas a valid hook installer (is_pre_commit_installed()), but the install step always ranpre-commit install. When onlyprekis on PATH, that raisesFileNotFoundError.This change:
pre-commit,prek)<installer> install --hook-type ...Fixes #2018
Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Cursor Grok following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsManual testing: unit tests cover only-prek, only-pre-commit, both (prompt), and neither (InitFailedError).
ruff checkandmypypass on the touched files. I did not run the full interactivecz initUI in a throwaway repo.Documentation Changes
uv run poe doclocally to ensure the documentation pages renders correctlyDocs change is a one-line note in
docs/commands/init.md. I did not rebuild the full mkdocs site.Expected Behavior
prekinstalled:cz initrunsprek installpre-commitinstalled: same as today (pre-commit install)InitFailedErrormentioning both toolsSteps to Test This Pull Request
prekonly (nopre-commiton PATH)cz initand select a hook typeprekand noFileNotFoundErrorpre-commit, then with both (should prompt)Additional Context
Owner-confirmed in #2018 (
issue-status: wait-for-implementation). Desired behavior is from the issue: treat the two tools as interchangeable, auto-select when only one is present, ask when both are.