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

Add -diff cli option for running precommit hooks against diffs #860

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

benmelz
Copy link
Contributor

@benmelz benmelz commented Jan 29, 2025

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.

Copy link
Owner

@sds sds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thank you for the clean PR and tests.

@sds sds merged commit b4d4ce0 into sds:main Jan 30, 2025
15 checks passed
@benmelz benmelz deleted the diff branch January 31, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants