Repository navigation
fix(hooks): run typos at the pre-commit stage only - #1493
Merged
Merged
Conversation
A hook with no stages runs at every stage, and typos passes filenames, so the commit-msg round hands it COMMIT_EDITMSG. Assert the pre-commit stage on the runner render, the scaffold render and the flake-generated consumer surface. RED on both portable renders (stages is absent); the consumer surface already passes, because git-hooks.nix defaults it to pre-commit. Refs: #1489
The hook carried no stages, so it ran at every hook stage — and since it passes filenames, the commit-msg round handed it COMMIT_EDITMSG. typos reads short letter runs inside abbreviated git SHAs as misspelled words, and git rebase --continue writes the rebase todo into that buffer as comment lines, so a legitimate rebase was refused over a comment that never enters the commit message. The workarounds it invites are editing git's own todo or --no-verify, which this repo forbids. Pin the stage in the yaml fragment of nix/hooks.nix, which renders both committed configs. The check and consumer fragments need nothing: git-hooks.nix already defaults the hook to pre-commit, so flake-generated direnv consumers were never affected — the test covers that surface anyway, so a future default change cannot reintroduce the trap silently. Scaffolded consumers WERE affected and are fixed by adopting this release. No coverage is lost: prek run --all-files and the CI lane run pre-commit. Refs: #1489
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.
Closes #1489
Problem
The
typoshook carried nostages:, so it ran at every hook stage — andbecause it has
pass_filenames: true, thecommit-msground handed itCOMMIT_EDITMSG.typosreads short letter runs inside abbreviated git SHAs asmisspelled words, and
git rebase --continuewrites the rebase todo into thatbuffer as comment lines, so a legitimate rebase was refused over a comment
that never enters the commit message. The content being committed is
irrelevant.
The workarounds it invites are editing git's own todo comment or
--no-verify,which this repo forbids.
Change
stages: [pre-commit]on theyamlfragment innix/hooks.nix, which rendersboth committed configs. That is what a source typo checker is for, and it
costs no coverage:
prek run --all-filesand the CI lint lane both run thepre-commitstage.One correction to the issue's diagnosis
#1489 proposed changing the
yaml,checkandconsumerfragments. Onlyyamlneeds it. I checked the rendered consumer surface directly:git-hooks.nix already defaults the hook to
pre-commit, in all six consumervariants that enable it — so flake-generated (direnv) consumers were never
affected, and an explicit pin there would be redundant. The test still asserts
that surface, so the guard does not depend on the default staying put.
Scaffolded consumers were affected (
scaffold = trueships the identicalunfiltered definition) and are fixed by adopting this release.
Verification
Live repro on this branch's worktree, before the fix — the
pre-commitroundpasses and the message round fails:
The identical commit after the fix: both rounds pass, exit 0.
Tests:
TestTyposRunsOnlyAtPreCommitcovers all three surfaces (runner render,scaffold render, consumer surface). RED on both portable renders before the fix
(
assert None == ['pre-commit']); the consumer case passed already, and Iconfirmed that is not vacuous. The existing drift gate covers the two committed
YAMLs. Full suite
1302 passed, 20 skipped;prek run --all-filesgreen.Note on the diff
The explanatory comments deliberately do not spell out the offending
trigrams or a real example SHA — writing them out makes
typosfail on thisvery PR's source files. typos 1.46.3 does not honour inline
spellchecker:disable-linedirectives (verified), and widening.typos.tomlwould weaken the linter repo-wide, so the comments describe the mechanism
instead of exhibiting it.
Follow-up filed
#1491 — the other two unfiltered
localhooks (sync-manifest,check-agent-identity) run 3x per commit for no benefit. Not bundled here:neither receives a filename, so neither is broken, and
check-agent-identityneeds a deliberate decision (its
consumerfragment is pinned topre-commitwhile its
yamlfragment is unpinned — the two surfaces disagree).Refs: #1489