Is it possible to pre-commit run on –from-ref/–to-ref and staged files together

Issue

When I invoke:

  • pre-commit run --from-ref origin/develop --to-ref HEAD: it runs on already committed files
  • pre-commit run: it runs on staged files

Is there a way to have pre-commit run on both in one command?

Solution

I’m not sure why you would ever want to do that — seems like an XY problem

that said, it’s always possible to utilize pre-commit run --files to run on whatever set of files you want to

combining the two:

(git diff --staged --name-only -z && git diff --name-only -z origin/develop...HEAD) | xargs -0 pre-commit run --files

disclaimer: I wrote pre-commit

Answered By – anthony sottile

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published