Repository navigation
feat: report only what a commit or branch changes with --staged and --base - #35
Draft
fcbwilliams wants to merge 2 commits into
Draft
fcbwilliams wants to merge 2 commits into
fcbwilliams wants to merge 2 commits into
Conversation
…-base A pre-commit or pre-push hook should judge the change being made, not every violation already in the tree, or a repository adopting a check cannot commit until it has fixed everything at once. `check --staged` reports only violations about files staged in the index, and `check --base <rev>` only those about files the commits since the merge base of <rev> and HEAD change. runChecks takes the same narrowing as `files`. Every check still reads the whole workspace, so cross-file checks keep their full view; violations about the repository's settings name no file and are always reported. The README gives a lint-staged recipe and the limits of a scoped run. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…an empty base A violation that names a directory (single-storybook's .storybook) is reported when a file under it changed, and one naming a path that does not exist (a missing config, a pattern) is always reported, rather than hidden from every scoped run. An empty --base, which compared HEAD with itself and passed, is refused. A failed git diff now says what git said and why the run needed it, and git may print up to 64 MiB. The README runs --staged straight from the pre-commit hook, since lint-staged skips commits that only delete files, and says what --base compares. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two exclusive options on
checknarrow what is reported to what a change touches:--stagedreports only violations about files staged in the index, for a pre-commit hook.--base <rev>reports only violations about files changed by the commits since the merge base of<rev>andHEAD, for a pre-push hook or a pull request.runCheckstakes the same narrowing asfilesand echoes it in the result.Every check still reads the whole workspace, so cross-file checks keep their full view; only what is reported is narrowed:
single-storybook's.storybook), when a file under that directory changed.The changed files come from
git diff --name-only --no-renames --relative -z. A rename counts as both paths, a deletion counts, and paths are relative to--cwd. An empty--base, or one starting with-, is refused. When git fails, the error says what git said and why the run needed it.The README section Checking only what changed covers the hook setup and the limits. It recommends running
--stageddirectly from.husky/pre-commit, because lint-staged skips commits that only delete files. It also notes that a scoped run cannot see a change that breaks a check at a file it did not touch, so CI should still run the full check.Why
A repository adopting a check today has to fix every existing violation before it can commit anything, because the tool judges the whole tree. Scoped runs let a hook block only the violations a change introduces, and the full run stays in CI. This came up in an assessment of using this tool for deterministic pre-commit enforcement, where the lack of a staged or changed-files mode was the main gap.
Tests
cli-command.integration.test.ts, git fixtures): staged files only, a staged deletion,--basereporting only the branch's own changes (merge-base semantics, including a base branch that moved on), a--cwdsubdirectory with JSONfiles, refusal of both flags together, an empty base, an option-like base and an unknown revision.pnpm lint:check,pnpm typecheckandpnpm testpass locally.🤖 Generated with Claude Code