chore(scripts): add local clang-format diff-gate helper#11
Merged
Conversation
536f825 to
389db95
Compare
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.
Local mirror of the CI clang-format diff-gate so developers can validate their changed lines before pushing.
Tools shipped
scripts/check_clang_format.py-- actual logic, Python.scripts/check_clang_format.sh/.bat-- thin wrappers (Linux/macOS/WSL/Git Bash + Windows cmd).scripts/git-hooks/pre-push-- versioned git hook that calls the check before every push.Usage
Opt in to the pre-push hook (one-time per clone)
That points git at the versioned hooks directory in the repo. No external dependency (Husky, pre-commit, etc.) -- just
core.hooksPath, which is built into git ≥ 2.9.To bypass the hook for a one-off push:
To disable entirely in your clone:
What the check does
Same exact logic as the existing CI clang-format job (
.github/workflows/build.yml):thirdparty/,*generated/,arena_generated.h,portable-file-dialogs.h..cpp,.cc,.h,.hpp.-p1 -style=file.Exit codes
0clean (or nothing in scope)1violations found (CI would fail here)2tooling missing (clang-format / clang-format-diff)Cross-platform notes
On Windows, the script auto-detects
clang-format-diff.pyunderProgram Files\LLVM\share\clang\when not on PATH (LLVM installer doesn't add it). On Linux/macOS,clang-format-diff-15(or any versioned variant) ships with the clang-format package.