Repository navigation
Make the local rustfmt gate runnable on Windows worktrees - #1485
Merged
Merged
Conversation
justinchuby
force-pushed
the
squad/fmt-gate-windows
branch
from
August 19, 2026 17:10
a550d8e to
504295c
Compare
CI runs `cargo fmt --all -- --check` on Linux and is fine. The local gate meant
to catch rustfmt drift before it lands was non-functional on Windows, where this
repo's agent workflow runs from git worktrees. Four independent defects, each
verified on this box:
1. Shell scripts checked out as CRLF (core.autocrlf=true, no .gitattributes
coverage), so bash refused to run them ("$'\r': command not found",
"set: pipefail: invalid option name").
2. install-hooks.sh assumed `$REPO_ROOT/.git/hooks`, but in a worktree .git is
a FILE, so it always bailed with "are you in a git repo?".
3. `cargo fmt --all` overflows the Windows ~32 KB command-line limit
(54 members / ~970 .rs files) and exits 1 with os error 206 — and the hook
suppressed stderr and suggested the same broken command as the fix.
4. Following from 1+2, no pre-commit hook was installed.
Changes:
- .gitattributes: pin `*.sh` and `scripts/hooks/*` to `eol=lf` and renormalize,
so bash scripts stay executable on Windows checkouts.
- scripts/install-hooks.sh: resolve the hooks dir via
`git rev-parse --git-common-dir` (works from the main checkout and any linked
worktree; hooks are shared across worktrees), handling a relative result.
- scripts/hooks/pre-commit: replace `cargo fmt --all -- --check` with a
Windows-safe check that maps staged .rs files to their owning workspace
packages and runs `cargo fmt -p <pkg> -- --check` (each package's own
edition, important for this mixed 2024/2021 workspace: rustfmt run with the
wrong edition mis-parses 2024-only syntax such as let chains and fails, so
only cargo's per-package edition is correct). The hook mirrors CI's scope:
staged files whose crate is NOT a workspace member (e.g. the root bench-*
crates, which `cargo fmt --all` does not cover either) are skipped with a
warning instead of blocked; if `cargo metadata` itself fails the hook warns
and lets the commit through rather than locking the author out. Stop
suppressing stderr; print a fix command that works on Windows.
- wiki/development/Testing and Verification.md: document that `cargo fmt --all`
does not work on Windows here and give the per-package alternative and the
hook installer.
This makes the local gate runnable on Windows; it does not claim to prevent
future drift.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
justinchuby
force-pushed
the
squad/fmt-gate-windows
branch
from
August 19, 2026 17:24
504295c to
817fb59
Compare
🔴 Benchmark Regression DetectedComparison of criterion micro-benchmarks: PR head vs merge-base, measured on the same runner in the same job (base first → PR second).
Visual flags: Host infoWhat this cannot catch
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1485 +/- ##
===========================================
- Coverage 82.10% 80.12% -1.99%
===========================================
Files 12 376 +364
Lines 5471 164127 +158656
Branches 5471 164127 +158656
===========================================
+ Hits 4492 131504 +127012
- Misses 780 27795 +27015
- Partials 199 4828 +4629
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Why
CI's Rust quality lane (
cargo fmt --all -- --check) runs on Linux and is fine.The local gate that is supposed to catch rustfmt drift before it lands is
non-functional on Windows — which is where this repo's agent workflow runs, from
git worktrees. The quality lane on
mainhas been repaired for rustfmt driftfour times (#1260, #1320, #1393, #1400). That the broken local gate is the cause
of those four repairs is a plausible inference, not something I measured — I only
verified that the local gate does not work. This PR makes the local gate
runnable on Windows. It does not claim to prevent future drift.
Defects (each verified on this Windows box)
Environment:
rustfmt 1.9.0-stable,cargo 1.97.1, Git-for-Windows bash 5.3,git config core.autocrlf = true, workspace = 54 members / 972 tracked.rsfiles, mixed-edition (52 on edition 2024, 2 on 2021).
Shell scripts check out as CRLF.
.gitattributesonly pinnedschema/inference_metadata.schema.json;*.shand the extension-lessscripts/hooks/*were unprotected, so all 14 tracked.shfiles + the hookshowed
w/crlf. Running one under bash printedscripts/install-hooks.sh: line 10: $'\r': command not foundandset: pipefail: invalid option name— unrunnable.install-hooks.shcannot work in a worktree. It usedHOOKS_DST="$REPO_ROOT/.git/hooks"and bailed if that dir was missing. In aworktree
.gitis a file, so it always errored "are you in a git repo?".cargo fmt --allfails on Windows regardless.cargo fmt --all -- --checkexits 1 with
The filename or extension is too long. (os error 206):cargo-fmt passes every path to one
rustfmt, overflowing the Windows ~32 KBcommand-line limit. Linux CI is unaffected (
ARG_MAX~2 MB). The oldpre-commitran this with2>/dev/nulland then told the userFix: cargo fmt --all— a command that also fails with os error 206.(This fails loudly with exit 1 — there is no false-green here.)
No hook was installed in this checkout — a consequence of 1+2.
Mixed-edition trap (why the fix uses
cargo fmt -p, not rawrustfmt): withthe wrong edition,
rustfmtmis-parses 2024-only syntax (e.g.letchains:error: let chains are only allowed in Rust 2024 or later) and fails. Onlycargo knows each package's declared edition, so driving the check per package is
the only correct approach. (An earlier claim of a silent exit-0 false green was
traced to a measurement artifact —
rustfmt … | Select-Object -First Ntruncatesthe pipeline and drops the native exit code — and has been withdrawn; the failure
is exit 1.)
Changes
.gitattributes— pin*.shandscripts/hooks/*toeol=lf(commentexplains a CRLF bash script is unexecutable) and renormalize. All 15 files now
report
i/lf w/lf attr/text eol=lf.scripts/install-hooks.sh— resolve the hooks dir viagit rev-parse --git-common-dir(the shared gitdir used by the main checkoutand every linked worktree), resolving a relative result to absolute. Keeps
--dryand the "does not clobber foreign hooks" property.scripts/hooks/pre-commit— map the staged.rsfiles to their owningworkspace packages and run
cargo fmt -p <pkg> -- --checkonly for those.Now mirrors CI's scope exactly:
bench-*crates) are skipped with a warning, becausecargo fmt --alldoes not cover them either. Blocking on a non-member would recreate the
os-error-206 failure shape (
cargo fmt -p <non-member>→ "not a member ofthe workspace") and wall people off behind drift they never introduced.
Membership is taken from
cargo metadata --no-deps(matched onmanifest_path, which is unambiguous — bare"name"keys also appear onevery dependency).
cargo metadataitself fails, the hook fails open (warns, lets thecommit through) — a format gate must not lock you out of the repo.
cargo fmt -p <pkg>(works onWindows).
wiki/development/Testing and Verification.md— state plainly thatcargo fmt --alldoes not work on Windows here; give the per-packagealternative and
bash scripts/install-hooks.sh.Verification (measured on this box)
install-hooks.sh --drysucceeds from the worktree and (relative-.gitbranch) from a normal checkout, both resolving to the same shared
…/onnx-genai/.git/hooks. Run under Git-for-Windows bash, which actuallyexecutes hooks. Note: WSL bash cannot run git in a Windows-created worktree at
all — the
.gitpointer holds aC:/…path WSL's git can't resolve; that is aWSL/Windows limitation affecting every git command there, not this script.
.rs→ commit blocked (exit 1), diffshown, fix
cargo fmt -p onnx-runtime-cpuinfoprinted; ran it → commitpassed.
bench-seqmajor).rs→ commit passed withthe "not a workspace member … CI's cargo fmt --all does not cover them
either" skip warning.
blocked, and the block came only from the member; the non-member was
skipped and the printed fix command works.
cargo metadatafailure (stub returning 101) → hook exited 0with the fail-open warning.
mainis clean by the new check: loopingcargo fmt -p <name> -- --checkover all 54 members → checked 54, failed 0, ignored 0.
hook only checks the staged packages, not all 54).
main-clean sweep, not theper-commit hook cost): two consecutive runs 26.1 s then 25.2 s,
consistent with an independent 23.1 s measurement. An earlier one-off 87.5 s
reading was a non-reproducible first-run outlier and is not representative.
Not touched
.github/workflows/ci.yml— CI is not broken; this is a local-gate fix..squad/.Rebase (onto latest main)
Rebased from base
4b1cabb8ontoorigin/mainat1557a355(which hadadvanced through #1482, #1173, #1420, #1487). The only conflict was in
wiki/development/Testing and Verification.md: #1482 translated the whole wikito Chinese (
lang: zh-CN), so my originally-English Windows-formatting sectioncollided with the now-Chinese baseline. Resolved by following the new Chinese
baseline — the added formatting/pre-commit documentation is written in Chinese
to match the surrounding prose, and none of #1482's translation was reverted.
Per project rules, code, commit messages and this PR title/body stay in English;
only that wiki body follows its file's language.
Checked that #1487's
docs/benchmarks/windows-cuda-runbook.mdneitheroverlaps nor conflicts with the wiki formatting note (the runbook covers CUDA
benchmarking and contains no formatting/hook content), so no cross-link was
needed.
After the rebase, re-ran the three end-to-end scenarios (member-block→fix→pass,
non-member-only→pass+skip-warning, mixed→blocked-only-by-member) and the
main-clean sweep (checked 54, failed 0) — all still correct. Testartifacts cleaned; working tree clean.