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.

Multi stage config is not fully installed from single 'pre-commit install'

See original GitHub issue

I’d like to use pre-commit and pre-push hooks. As I try to keep commit-time low, I’d like to only perform a subset before the commit stage and the full set before the push stage. I can create a .pre-commit-config.yaml that contains all hooks and use the stages keyword, to assign which hooks should be run at which stage. If I’m not mistaken, I’ll need to run pre-commit install twice, once per stage though.

Is there currently an option that allows easy installation (i.e. run pre-commit install once without options) and have all hooks installed according to the specification in the config file? This would also make the automatic enabling in new repositories easier, unless that already takes care of such cases somehow.

Here is a minimal example for the .pre-commit-config.yaml with one hook run only before commits and one only before pushes:

default_stages: [commit]
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
      -   id: check-merge-conflict
      -   id: trailing-whitespace
          stages: [push]

You’ve said somewhere else, that you would prefer not to change the default behavior of install (because some users might actively use separate installs for different stages). But perhaps, adding a --all or --all-stages flag could solve the issue?

Relates to #364 and #768

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Jan 11, 2021

init-templatedir takes the same arguments as install so the solution is the same still

0reactions
asottilecommented, Jan 11, 2021

notably pre-commit init-templatedir whatever --hook-stage commit --hook-stage push ...

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 can I configure pre-commit tool to rely on a single ...
Due to this I am wondering if there is another setup which would allow me to have a centralized pre-commit repository that defines...
Read more >
lint-staged - npm
Install lint-staged on the monorepo root level, and add separate configuration files in each package. When running, lint-staged will always use ...
Read more >
Pre-commit Hook - Prettier
You can use Prettier with a pre-commit tool. This can re-format your files that are marked as “staged” via `git add` before you...
Read more >
Pre-commit hooks you must know - Towards Data Science
The Python package has a plugin-system to create git pre-commit hooks automatically. It's not only for Python projects but for any project.
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