Skip to content

chore(scripts): add local clang-format diff-gate helper#11

Merged
virtexalejandro merged 1 commit into
mainfrom
chore/clang-format-local-check
May 12, 2026
Merged

chore(scripts): add local clang-format diff-gate helper#11
virtexalejandro merged 1 commit into
mainfrom
chore/clang-format-local-check

Conversation

@virtexalejandro
Copy link
Copy Markdown
Contributor

@virtexalejandro virtexalejandro commented May 12, 2026

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

python scripts/check_clang_format.py        # check vs origin/main
python scripts/check_clang_format.py --fix  # apply fixes in place
python scripts/check_clang_format.py --base HEAD~1  # different base ref

Opt in to the pre-push hook (one-time per clone)

git config core.hooksPath scripts/git-hooks

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:

git push --no-verify

To disable entirely in your clone:

git config --unset core.hooksPath

What the check does

Same exact logic as the existing CI clang-format job (.github/workflows/build.yml):

  • Diff-gate: only validates lines modified vs a base ref, not whole files.
  • Same exclusions: thirdparty/, *generated/, arena_generated.h, portable-file-dialogs.h.
  • Same scope: .cpp, .cc, .h, .hpp.
  • Same flags: -p1 -style=file.

Exit codes

  • 0 clean (or nothing in scope)
  • 1 violations found (CI would fail here)
  • 2 tooling missing (clang-format / clang-format-diff)

Cross-platform notes

On Windows, the script auto-detects clang-format-diff.py under Program 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.

@virtexalejandro virtexalejandro force-pushed the chore/clang-format-local-check branch from 536f825 to 389db95 Compare May 12, 2026 12:49
@virtexalejandro virtexalejandro merged commit 2e4a119 into main May 12, 2026
9 checks passed
@virtexalejandro virtexalejandro deleted the chore/clang-format-local-check branch May 12, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant