From: Misomosi Date: Sun, 3 Nov 2024 19:42:41 +0000 (-0500) Subject: Add clangformat commit hook option X-Git-Url: http://git.misomosispi.com/?a=commitdiff_plain;h=9594cc557d0abe7374df1f0aa2001ee2e05c494f;p=dotfiles.git Add clangformat commit hook option --- 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 -- ```