0

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?

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119

1 Answers1

1

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

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • My motivation is having parity between local dev and CI. In local dev I want to run on staged files, in CI I want it to run on commits above `develop`. I want to have the same command for both, and ideally it's a one-liner. What you suggested will work, so thank you! – Intrastellar Explorer Nov 12 '22 at 01:09
  • 1
    that doesn't seem like a good idea -- you're going to make local slower for no reason – anthony sottile Nov 12 '22 at 01:34