question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: if used with pre-commit and additional args -> Invalid value for "--msg-filename"

See original GitHub issue

When I use gitlint with pre-commit and want to add --extra-path for custom rules like so:

repos:
  - repo: https://github.com/jorisroovers/gitlint
    rev: c359748723a52f6c0c5f87c3b71749f75179ca74  # frozen: v0.14.0
    hooks:
      - id: gitlint
        args: [--extra-path pre-commit-helper.py]

I get the error:

gitlint..................................................................Failed
- hook id: gitlint
- exit code: 253

Usage: gitlint [OPTIONS] COMMAND [ARGS]...
Try "gitlint --help" for help.

Error: Invalid value for "--msg-filename": Could not open file: --extra-path pre-commit-helper.py: No such file or directory

*** Exit Code: 1 ***

Reason for this is that my added args [--extra-path pre-commit-helper.py] are appended to the end after the entry-point. In gitlint’s .pre-commit-hooks.yaml the entry contains args and --msg-filename as one expects a value to follow.

As a workaround you have to overwrite the entry in .pre-commit-config.yaml like so:

  - repo: https://github.com/jorisroovers/gitlint
    rev: c359748723a52f6c0c5f87c3b71749f75179ca74  # frozen: v0.14.0
    hooks:
      - id: gitlint
        entry: gitlint
        args: [--extra-path, pre-commit-helper.py, --staged, --msg-filename]

As a fix you have to move the args from entry to args. I will submit a PR. Sure you then have to specify them again, if you overwrite them, but that gives you more granular control as a user and its cleaner IMHO.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Cielquancommented, Oct 31, 2020

I’m not sure whether there’s really any difference with the suggested change: an error will occur in both cases when you only specify args without also specifying entry in your .pre-commit-hooks.yaml, no matter what’s in gitlint’s default .pre-commit-hooks.yaml. In either case, you’ll need to use the documented workaround. I haven’t tried it, but from what I can tell, gitlint’s error message will also be the same in both cases.

I will look into it probably tomorrow.

So I looked into it and to be 100% sure I tested it with my PR-fork also: With the current .pre-commit-hookss.yaml you are 100% right. You have to specify both: entry and args if you want to add custom args to the hook. But if you work with my PR-version you only need to specify the args section and don’t need to specify entry also, because its just the vanilla command without any argument. So you don’t have to overwrite it.

In both cases you have to add the --msg-filename argument at the end of cause.

IMHO the PR-version is less confusing and I would also state it more explicit that one have to add --msg-filename to args if one overwrites them.

If you want to take the PR I would also update the docs, if you want.

1reaction
Cielquancommented, Oct 30, 2020

So this work-around is already documented: https://jorisroovers.com/gitlint/#using-gitlint-through-pre-commit

My bad. I use pre-commit for some time so I skipped this part.

I’m not sure whether there’s really any difference with the suggested change: an error will occur in both cases when you only specify args without also specifying entry in your .pre-commit-hooks.yaml, no matter what’s in gitlint’s default .pre-commit-hooks.yaml.

In either case, you’ll need to use the documented workaround. I haven’t tried it, but from what I can tell, gitlint’s error message will also be the same in both cases.

I will look into it probably tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-commit hook fails when adding args · Issue #109 - GitHub
I've set up my .pre-commit-config.yml like this: default_stages: [commit ... Error: Invalid value for "--msg-filename": Could not open file: ...
Read more >
pre-commit
We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks...
Read more >
How to solve pre-commit asserttion error on ubuntu 22.04
I have installed a Django project with the cookie-cutter. and now I have got an error when I want to commit my changes....
Read more >
Usage — pydocstyle 6.1.1 documentation
Options: --version show program's version number and exit -h, --help show this help message and exit -e, --explain show explanation of each error...
Read more >
Improve Code Quality with Git Hooks and Pre-commit
Pre -commit hooks tutorial to improve code quality and reduce bugs. ... of this post for an example .pre-commit-config.yaml file I use as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found