Skip to content

cz init raises FileNotFoundError for pre-commit if only prek is installed #2018

@mcsitter

Description

@mcsitter

Description

During cz init, hook installation checks whether pre-commit or prek is available, but always executes pre-commit install. If only prek is installed, detection succeeds but execution fails, resulting in a FileNotFoundError.

Steps to reproduce

  1. Install commitizen and prek. pre-commit should not be on Path.
  2. Run cz init
  3. Just hit enter on the question ? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) [commit-msg]
  4. Get FileNotFoundError: [Errno 2] No such file or directory: 'pre-commit'

Current behavior

In the init function is a check to ensure that a pre-commit tool is available, but it checks for pre-commit and prek, while the install command is invoked with pre-commit.

Desired behavior

  • Treat pre-commit and prek as interchangeable hook installers.
  • If only one is installed: use it automatically.
  • If both are installed: ask the user to choose.

Screenshots

No response

Environment

Commitizen Version: 4.16.3
Python Version: 3.12.13 (main, Jun 11 2026, 04:55:13) [GCC 14.2.0]
Operating System: Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions