Skip to content

Commit 8d2477c

Browse files
committed
hook: Use clang-format with highest version
Also fixes some inconsistencies.
1 parent dd03238 commit 8d2477c

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

hooks/pre-commit

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
#!/bin/sh
22

3-
git clang-format --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs'
3+
name=""
4+
version="14.0.0"
45

5-
git diff --name-only --diff-filter=ACMR | while read -r file
6-
do
6+
for file in $(find $(echo "$PATH" | sed 's/:/ /g') -type f -executable -name 'git-clang-format*'); do
7+
cur_name="$(basename "$file" | sed 's/^git-//')"
8+
cur_version="$("$cur_name" --version | awk '{print $3}')"
9+
10+
if [ "$(printf '%s\n' "$cur_version" "$version" | sort -V | tail -n 1)" = "$cur_version" ]; then
11+
version="$cur_version"
12+
name="$cur_name"
13+
fi
14+
done
15+
16+
if [ -z "$name" ]; then
17+
echo "Could not find a suitable clang-format installation. Install clang-format with at least version $version"
18+
exit 1
19+
fi
20+
21+
changed_files="$(git "$name" --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs')"
22+
23+
echo "$changed_files"
24+
25+
echo "$changed_files" | tail -n +2 | while read -r file; do
726
git add -- "$file"
827
done

0 commit comments

Comments
 (0)