hook: Update pre-commit git hook
This commit is contained in:
parent
ecf2f564f7
commit
ab8e267e28
|
@ -1,25 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
if clang-format --version | grep -q 'version 11\.'; then
|
|
||||||
CLANG_FORMAT_EXECUTABLE="clang-format"
|
|
||||||
else
|
|
||||||
CLANG_FORMAT_EXECUTABLE="clang-format-11"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v $CLANG_FORMAT_EXECUTABLE &> /dev/null
|
changedFiles="$(git clang-format --extensions cpp,h --style file --staged -q --diffstat -- ':!src/FreeRTOS' ':!src/libs')"
|
||||||
then
|
git clang-format --extensions cpp,h --style file --staged -q -- ':!src/FreeRTOS' ':!src/libs'
|
||||||
echo $CLANG_FORMAT_EXECUTABLE does not exist, make sure to install it
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
for FILE in $(git diff --cached --name-only)
|
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 1 | while read -r file; do
|
||||||
do
|
git add -- "$file"
|
||||||
if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then
|
|
||||||
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_EXECUTABLE
|
|
||||||
$CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE
|
|
||||||
git add -- $FILE
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue