Skip to content

Commit c634a4e

Browse files
committed
hook: Use clang-format with highest version
1 parent ab8e267 commit c634a4e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

hooks/pre-commit

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
#!/bin/sh
22

3-
changedFiles="$(git clang-format --extensions cpp,h --style file --staged -q --diffstat -- ':!src/FreeRTOS' ':!src/libs')"
4-
git clang-format --extensions cpp,h --style file --staged -q -- ':!src/FreeRTOS' ':!src/libs'
3+
minVersion="14.0.0"
54

6-
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 1 | while read -r file; do
5+
for file in $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'git-clang-format*'); do
6+
curName="$(basename "$file" | sed 's/^git-//')"
7+
curVersion="$("$curName" --version | cut -d ' ' -f 3)"
8+
9+
if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then
10+
name="$curName"
11+
version="$curVersion"
12+
fi
13+
done
14+
15+
if [ -z "$name" ]; then
16+
echo "Could not find a suitable clang-format installation. Install clang-format that includes the git-clang-format script, with at least version $minVersion"
17+
exit 1
18+
fi
19+
20+
args='-q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs'
21+
22+
changedFiles="$(git "$name" --diffstat $args)"
23+
git "$name" $args
24+
25+
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 2 | while read -r file; do
726
git add -- "$file"
827
done

0 commit comments

Comments
 (0)