-2

Let's say we have some hook for a tool like Black (formatter for Python). Let's say we upgrade the hook to a version of the tool that introduces significant changes to its behavior.

Ideally we would want to re-run the hook on all the files in the repository, not just the next batch of modified ones. Ideally we would detect this case automatically and perform the repo-wide run either as part of the upgrade or as part of CI validations. The rest of the time pre-commit's normal behavior (only checking modified files) is fine.

How can we best achieve the ideal scenario?

One solution that comes to mind is to wrap pre-commit autoupdate, but as far as I can tell, that can only run all hooks on all files. It would be nice to select only the upgraded hooks.

In CI one solution is to trigger a job when the pre-commit file gets modified, but that also has issues:

  • We still don't know which hook to run.
  • We will trigger for changes to config as well as hook upgrades. This may or may not be desirable.
Ilia Kurenkov
  • 637
  • 5
  • 12
  • Because this is suggesting making a very simple task, running two commands, into making a very complex system to basically achievement the same result. – mrswats May 01 '23 at 10:07

1 Answers1

2

You can just use pre-commit run --all-files

https://pre-commit.com/#pre-commit-run

No need for complicated logic here.

mrswats
  • 155
  • 5
  • Thanks for the answer! Could you expand on it a bit please? Do you mean we run `--all-files` for every CI job, even those triggered by changing only a few files? If yes, won't this slow down the CI significantly for larger repos? – Ilia Kurenkov May 01 '23 at 06:57
  • Yes, that's the whole point. You want to akways check every file. I don't think performances is an issue here. It would have to be a very big repo for it to really matter. – mrswats May 01 '23 at 10:06