2021-04-18 16:20:16 +00:00
|
|
|
#!/bin/bash
|
2021-05-01 17:36:27 +00:00
|
|
|
if clang-format --version | grep -q 'version 11\.'; then
|
|
|
|
CLANG_FORMAT_EXECUTABLE="clang-format"
|
|
|
|
else
|
|
|
|
CLANG_FORMAT_EXECUTABLE="clang-format-11"
|
|
|
|
fi
|
|
|
|
|
2021-05-03 11:12:33 +00:00
|
|
|
if ! command -v $CLANG_FORMAT_EXECUTABLE &> /dev/null
|
|
|
|
then
|
|
|
|
echo $CLANG_FORMAT_EXECUTABLE does not exist, make sure to install it
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-18 16:20:16 +00:00
|
|
|
for FILE in $(git diff --cached --name-only)
|
|
|
|
do
|
|
|
|
if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then
|
2021-05-01 17:36:27 +00:00
|
|
|
echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
|
|
|
|
$CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
|
2021-04-18 16:20:16 +00:00
|
|
|
git add -- $FILE
|
|
|
|
elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then
|
2021-05-01 17:36:27 +00:00
|
|
|
echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE
|
|
|
|
$CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
|
2021-04-18 16:20:16 +00:00
|
|
|
git add -- $FILE
|
|
|
|
fi
|
|
|
|
done
|