-
-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hook: Use clang-format with highest version
Also fixes some inconsistencies.
- Loading branch information
1 parent
dd03238
commit 842c26d
Showing
1 changed file
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
#!/bin/sh | ||
|
||
git clang-format --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs' | ||
name="" | ||
version="14.0.0" | ||
|
||
git diff --name-only --diff-filter=ACMR | while read -r file | ||
do | ||
for file in $(find $(echo "$PATH" | sed 's/:/\n/g') -type f -executable -name 'git-clang-format*'); do | ||
cur_name="$(basename "$file" | sed 's/^git-//')" | ||
cur_version="$("$cur_name" --version | awk '{print $3}')" | ||
|
||
if [ "$(printf '%s\n' "$cur_version" "$version" | sort -V | tail -n 1)" = "$cur_version" ]; then | ||
version="$cur_version" | ||
name="$cur_name" | ||
fi | ||
done | ||
|
||
if [ -z "$name" ]; then | ||
echo "Could not find a suitable clang-format installation. Install clang-format with at least version $version" | ||
exit 1 | ||
fi | ||
|
||
changed_files="$(git "$name" --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs')" | ||
|
||
echo "$changed_files" | ||
|
||
echo "$changed_files" | tail -n +2 | while read -r file; do | ||
git add -- "$file" | ||
done |