Skip to content

Commit

Permalink
Update pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed Jan 9, 2023
1 parent 09db67e commit 7cfe2b9
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
#!/bin/bash
if clang-format --version | grep -q 'version 11\.'; then
CLANG_FORMAT_EXECUTABLE="clang-format"
else
CLANG_FORMAT_EXECUTABLE="clang-format-11"
fi
#!/bin/sh

if ! command -v $CLANG_FORMAT_EXECUTABLE &> /dev/null
then
echo $CLANG_FORMAT_EXECUTABLE does not exist, make sure to install it
exit 1
fi
git clang-format --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs'

for FILE in $(git diff --cached --name-only)
git diff --name-only --diff-filter=ACMR | while read -r file
do
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
git add -- "$file"
done

0 comments on commit 7cfe2b9

Please sign in to comment.