diff options
| author | Avamander <avamander@gmail.com> | 2021-05-01 17:36:27 (GMT) |
|---|---|---|
| committer | JF002 <JF002@users.noreply.github.com> | 2021-07-24 13:55:52 (GMT) |
| commit | 10ef3a749ede4a27fe162bd730b26fb778ffaa85 (patch) | |
| tree | 2f19b2556539347d42aa32ce111d16c2471f6f1b /hooks | |
| parent | a1a6eae43f5995e21ff3d535094a6350e1031804 (diff) | |
Added autodetection for clang-format version
Diffstat (limited to 'hooks')
| -rwxr-xr-x | hooks/pre-commit | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/hooks/pre-commit b/hooks/pre-commit index 2e918a1..15961f1 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,13 +1,19 @@ #!/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) do if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then - echo Autoformatting $FILE with clang-format - clang-format-11 -style=file -i -- $FILE + 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 - clang-format-11 -style=file -i -- $FILE + echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE + $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE git add -- $FILE fi done |
