Skip to content

Revision filename for post_write_hooks options passed in wrong position #819

@maresb

Description

@maresb

Describe the bug

While trying to run pre-commit as a post-write hooks, I encountered a failure. My config was

hooks = pre-commit
pre-commit.type = console_scripts
pre-commit.entrypoint = pre-commit
pre-commit.options = run --files

The failure occurred because the pre-commit command was being run as

pre-commit /path/to/revision_file.py run --files

instead of

pre-commit run --files /path/to/revision_file.py

Expected behavior

The documentation states:

The path of the revision file is sent as a single positional argument to the script after the options.

However, checking the code, this is not the case, as it is being passed as the first argument.

Additional note

The command line options are being split using str.split(), but for command line options it's much better to use shlex.split() since that properly handles things like quoting.

PR incoming...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinguse casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions