Skip to content

guards: pre-commit hooks read each changed file whole, so a change is blamed for backlog it did not introduce #16238

Description

@mrveiss

The class

Several pre-commit hooks read each changed file whole. So editing one line of a legacy module makes the commit, or the PR, answerable for that file's entire backlog. The hook fails on violations that blame attributes to other commits, and the change being made has nothing to do with them.

It is costly because it blocks fixes to old files, and old files are where security fixes land. #16186 recorded a 2-line git-scrubbing fix (#16179) that could not land for a day, because staging the file made it answerable for a 117-line function the diff never touched.

Precedent, and why it isn't enough

#13950 scoped pre-commit-hardcoded-values to added lines, and #14051 did the same for no-print-console. Both go through pipeline-scripts/check-pre-commit-hook-pr.sh --changed-lines-only. Both apply only in CI. code-quality.yml says so directly: "the pre-commit stage and a direct run still scan whole files." Hardcoded-values gets away with that because it has a baseline file for pre-existing hits. A hook with no CI step and no baseline still blocks the local commit, which is where each witness below was blocked.

Members

Principle for every member

A check that runs on a change should judge what the change added. The whole-file backlog stays visible by running the hook directly, and each hook should say which of the two it's doing, so a clean scoped run is never read as a clean file.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions