Add `-diff` cli option for running precommit hooks against diffs by benmelz · Pull Request #860 · sds/overcommit
For example, running overcommit --diff main from a feature branch will run pre-commit hooks against the diff between the two branches.
I was able to very easily leverage existing code for the bulk of the feature - this is mainly just adding the cli option, a hook context to do the execution and some tests based on the existing --run-all test.
For background, my team is responsible for a couple of really old, really large rails apps. Getting them completely in compliance with our various linters is a huge task that isn't getting done anytime soon (things are funky to the point that we've even observed breakages with "safe" auto-correct functions).
I introduced/started heavily encouraging overcommit so that we at least don't add new linting offenses and things will naturally improve over time. It's been great, but offenses still slip through though here and there, especially with juniors who might be getting away with not having a local install (and/or abusing OVERCOMMIT_DISABLE=1).
An option like this would allow me to leverage the very useful "only apply to changed lines" logic within a ci environment and help enforce my desired "no new linting offenses" policy.