# Truecolor SGR escapes in lefthook's banner render as literal garbage in some # clients (e.g. fork); plain output keeps it readable. colors: false commit-msg: commands: commitlint: run: npx commitlint --edit {1} # Format staged C# files and re-stage the result (CSharpier's documented lefthook # pattern). --no-cache: the cache keys whole-tree runs, which would mismatch the # staged-paths-only invocation here. CI's `csharpier check` is the safety net. # Partial staging (git add -p) is safe: lefthook hides unstaged changes during # pre-commit and restores them after (since 1.3.0), so stage_fixed only ever # stages the formatted staged content. pre-commit: parallel: true commands: csharpier: glob: "*.{cs,csx}" run: dotnet csharpier format --no-cache {staged_files} stage_fixed: true # Fix + format staged JS/TS files and re-stage (Biome's documented lefthook # pattern). --unsafe: apply every autofix so fixable rules never block a commit; # rules whose unsafe fix is genuinely hazardous are set to fix:none in biome.jsonc. # --no-errors-on-unmatched: staged files outside biome's scope must not fail the # hook; CI's `biome ci` is the safety net. biome: glob: "*.{js,ts,cjs,mjs,cts,mts,jsx,tsx,vue,json,jsonc,css}" run: npx @biomejs/biome check --write --unsafe --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files} stage_fixed: true # Local guard against accidental direct pushes to master. # # The "master" ruleset requires a PR + approval for the normal case (fork/external PRs). # GitHub forbids self-approval, so own PRs rely on an OrganizationAdmin "always" bypass to # merge once CI is green. That bypass also silently permits a stray push straight to # master — this hook sits below the bypass layer and is the only thing that catches it. # # `only: ref: master` runs only while master is checked out, so a push from master always # fails here. A deliberate direct push means temporarily removing this block by hand. pre-push: commands: block-master: only: - ref: master # Single-quoted echoes: lefthook wraps the script in sh -c "...", so embedded # double-quotes would break that outer quoting and swallow the exit code. run: | echo '✋ Push blocked: master is checked out, so this hook blocks every push from it.' echo ' Pushing/deleting another branch? Switch off master first (git switch ).' echo ' Really pushing to master? Temporarily remove the block-master hook in lefthook.yml.' exit 1