-
-
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
- Loading branch information
1 parent
4385c88
commit 5b3db43
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 | ||
|
||
changedFiles="$(git clang-format --extensions cpp,h --style file --staged -q --diffstat -- ':!src/FreeRTOS' ':!src/libs')" | ||
git clang-format --extensions cpp,h --style file --staged -q -- ':!src/FreeRTOS' ':!src/libs' | ||
minVersion="14.0.0" | ||
|
||
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 1 | while read -r file; do | ||
for file in $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'git-clang-format*'); do | ||
curName="$(basename "$file" | sed 's/^git-//')" | ||
curVersion="$("$curName" --version | cut -d ' ' -f 3)" | ||
|
||
if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then | ||
name="$curName" | ||
version="$curVersion" | ||
fi | ||
done | ||
|
||
if [ -z "$name" ]; then | ||
echo "Could not find a suitable clang-format installation. Install clang-format that includes the git-clang-format script, with at least version $minVersion" | ||
exit 1 | ||
fi | ||
|
||
args='-q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs' | ||
|
||
changedFiles="$(git "$name" --diffstat $args)" | ||
git "$name" $args | ||
|
||
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 2 | while read -r file; do | ||
git add -- "$file" | ||
done |