Skip to content

Commit 10ef3a7

Browse files
AvamanderJF002
authored andcommitted
Added autodetection for clang-format version
1 parent a1a6eae commit 10ef3a7

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

hooks/pre-commit

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/bin/bash
2+
if clang-format --version | grep -q 'version 11\.'; then
3+
CLANG_FORMAT_EXECUTABLE="clang-format"
4+
else
5+
CLANG_FORMAT_EXECUTABLE="clang-format-11"
6+
fi
7+
28
for FILE in $(git diff --cached --name-only)
39
do
410
if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then
5-
echo Autoformatting $FILE with clang-format
6-
clang-format-11 -style=file -i -- $FILE
11+
echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
12+
$CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
713
git add -- $FILE
814
elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then
9-
echo Autoformatting $FILE with clang-format
10-
clang-format-11 -style=file -i -- $FILE
15+
echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
16+
$CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
1117
git add -- $FILE
1218
fi
1319
done

0 commit comments

Comments
 (0)