summaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorAvamander <avamander@gmail.com>2021-05-01 20:36:27 +0300
committerJF002 <JF002@users.noreply.github.com>2021-07-24 15:55:52 +0200
commit10ef3a749ede4a27fe162bd730b26fb778ffaa85 (patch)
tree2f19b2556539347d42aa32ce111d16c2471f6f1b /hooks
parenta1a6eae43f5995e21ff3d535094a6350e1031804 (diff)
Added autodetection for clang-format version
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/pre-commit14
1 files changed, 10 insertions, 4 deletions
diff --git a/hooks/pre-commit b/hooks/pre-commit
index 2e918a17..15961f19 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -1,13 +1,19 @@
#!/bin/bash
+if clang-format --version | grep -q 'version 11\.'; then
+ CLANG_FORMAT_EXECUTABLE="clang-format"
+else
+ CLANG_FORMAT_EXECUTABLE="clang-format-11"
+fi
+
for FILE in $(git diff --cached --name-only)
do
if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then
- echo Autoformatting $FILE with clang-format
- clang-format-11 -style=file -i -- $FILE
+ echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
+ $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
git add -- $FILE
elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then
- echo Autoformatting $FILE with clang-format
- clang-format-11 -style=file -i -- $FILE
+ echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
+ $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
git add -- $FILE
fi
done