From 9594cc557d0abe7374df1f0aa2001ee2e05c494f Mon Sep 17 00:00:00 2001 From: Misomosi Date: Sun, 3 Nov 2024 14:42:41 -0500 Subject: [PATCH] Add clangformat commit hook option --- .config/git/hooks/pre-commit | 9 +++++++++ README.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/.config/git/hooks/pre-commit b/.config/git/hooks/pre-commit index b110b2e..e79b28a 100755 --- a/.config/git/hooks/pre-commit +++ b/.config/git/hooks/pre-commit @@ -34,4 +34,13 @@ If you know what you are doing you can disable this check using: EOF exit 1 fi + +# If clangformat.style is explicitly defined globally or in repo, +# I explicitly opt in to run git clang-format. I usually only do +# this for external projects because they have different code styles +# and are usually more strict about it than I am. Oh well. +if git config --get clangformat.style ; then + git clang-format --staged $against + git add "$(git rev-parse --show-toplevel)" +fi exec git diff-index --check --cached $against -- diff --git a/README.md b/README.md index adffacb..2032f2a 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,15 @@ If you know what you are doing you can disable this check using: EOF exit 1 fi + +# If clangformat.style is explicitly defined globally or in repo, +# I explicitly opt in to run git clang-format. I usually only do +# this for external projects because they have different code styles +# and are usually more strict about it than I am. Oh well. +if git config --get clangformat.style ; then + git clang-format --staged $against + git add "$(git rev-parse --show-toplevel)" +fi exec git diff-index --check --cached $against -- ``` -- 2.49.1