]> localhost Git - dotfiles.git/commitdiff
Add clangformat commit hook option
authorMisomosi <[email protected]>
Sun, 3 Nov 2024 19:42:41 +0000 (14:42 -0500)
committerMisomosi <[email protected]>
Sun, 3 Nov 2024 19:42:41 +0000 (14:42 -0500)
.config/git/hooks/pre-commit
README.md

index b110b2ecf56643e0b4ef3d24874ab88a5512081e..e79b28a98f04cc563c51cf72d7fca60e9dc84fb9 100755 (executable)
@@ -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 --
index adffacb5a004f59f891d35a7e3986578d30dcbf2..2032f2a52f64159dac90c4b7e87ac59d7a4e6cfa 100644 (file)
--- 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 --
 ```