Skip to content

commit-msg hooks don't receive the commit message file argument #1194

@Jamie-BitFlight

Description

@Jamie-BitFlight

Bug Description

When running commit-msg stage hooks, prek does not pass the commit message file path to the hook. The hook receives only the configured args from .pre-commit-config.yaml, but not the commit message file that git provides.

Expected Behavior

For commit-msg hooks, prek should append the commit message file path (provided by git via $1) to the hook's arguments.

Actual Behavior

The commit message file is not passed. Hooks that require the input file (like conventional-pre-commit) fail with:

error: the following arguments are required: input

Steps to Reproduce

  1. Create .pre-commit-config.yaml:
repos:
  - repo: https://github.com/compilerla/conventional-pre-commit
    rev: v4.3.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]
        args:
          - --strict
          - --force-scope
  1. Install hooks: prek install --hook-type commit-msg
  2. Stage a file: git add somefile
  3. Try to commit: git commit -m "feat: test"
  4. Observe error: conventional-pre-commit: error: the following arguments are required: input

Additional Context

  • prek version: 0.2.19
  • OS: Linux (Ubuntu)
  • Calling the git hook directly works: .git/hooks/commit-msg /tmp/test_msg.txt
  • During actual commits, the file is not passed

Investigation

The .git/hooks/commit-msg script runs:

exec "$PREK" hook-impl --hook-type=commit-msg --hook-dir "$HERE" -- "$@"

Git passes the commit message file as $@, but it seems prek's hook-impl doesn't forward this to the individual hooks.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions