Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit run foo does not work for pre-push hook foo #1078

Closed
zanieb opened this issue Jul 9, 2019 · 9 comments
Closed

pre-commit run foo does not work for pre-push hook foo #1078

zanieb opened this issue Jul 9, 2019 · 9 comments
Labels

Comments

@zanieb
Copy link

zanieb commented Jul 9, 2019

Hi!

It appears that one cannot run run pre-push hooks ids with pre-commit run.

e.g.

- repo: local
  hooks:
  - id: hadolint
    name: Hadolint
    description: Haskell-based Docker image linter
    language: docker_image
    types:
      - dockerfile
    entry: --entrypoint /bin/hadolint hadolint/hadolint:latest --ignore DL3013 --ignore DL3018 --ignore DL3008 -
  -   id: pytest
      name: Python tests
      entry: --entrypoint pytest mycompany/image:0.13 -v
      language: docker_image
      types: [python]
      stages: [push]
~/
❯ pre-commit run pytest
No hook with id `pytest`

~/
❯ pre-commit run hadolint
Hadolint.............................................(no files to check)Skipped

If I remove stages: [push] I can run pytest with the same command as above.

@asottile
Copy link
Member

asottile commented Jul 9, 2019

Try pre-commit run --help -- there's a --hook-stage / --source / --origin that's used for pre-push hooks

@zanieb
Copy link
Author

zanieb commented Jul 9, 2019

Ah, okay that's super helpful. Thanks!

Why does run not search for pre-push hooks by default?

@asottile
Copy link
Member

asottile commented Jul 9, 2019

--hook-stage defaults to commit

@zanieb
Copy link
Author

zanieb commented Jul 9, 2019

I understand, I'm asking why the decision was made to only search a single stage when an id is specified. It seems like the typical use-case of pre-commit run <id> would be stage agnostic whereas pre-commit run --hook-stage <stage> makes a lot of sense.

@asottile
Copy link
Member

asottile commented Jul 9, 2019

stages were added later (it would have been backward incompatible to change the meaning there) and some of the stages don't make sense to be run alone (they require extra information (--source / --origin for pre-push, --commit-msg-filename for the commit message ones, etc.) -- the commit stage is the only one which doesn't require anything special.

Note that pre-commit is an alias for pre-commit run is an alias for pre-commit run --hook-stage commit

@zanieb
Copy link
Author

zanieb commented Jul 9, 2019

Ah, that makes a lot of sense (thanks again for the quick replies). It would be interesting to automatically search other hook-stages given an id that does not exist in commit. I assume the error that extra information is required would appear as needed and it wouldn't change the existing interfaces. What do you think?

@asottile
Copy link
Member

asottile commented Jul 9, 2019

I'd rather not, that would be an incompatible change with current usages -- I'd rather "for stage {stage}" to the not found message

@zanieb
Copy link
Author

zanieb commented Jul 9, 2019

See #1079

@asottile
Copy link
Member

asottile commented Jul 9, 2019

sounds great! thanks for the patch 🎉

@zanieb zanieb closed this as completed Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants