Added autodetection for clang-format version

This commit is contained in:
Avamander 2021-05-01 20:36:27 +03:00 committed by JF002
parent a1a6eae43f
commit 10ef3a749e

View file

@ -1,13 +1,19 @@
#!/bin/bash #!/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) for FILE in $(git diff --cached --name-only)
do do
if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then
echo Autoformatting $FILE with clang-format echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
clang-format-11 -style=file -i -- $FILE $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
git add -- $FILE git add -- $FILE
elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then
echo Autoformatting $FILE with clang-format echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
clang-format-11 -style=file -i -- $FILE $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
git add -- $FILE git add -- $FILE
fi fi
done done