Skip to content

Commit 8752c63

Browse files
committed
hook: Use clang-format with highest version
1 parent 4385c88 commit 8752c63

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

hooks/pre-commit

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#!/bin/sh
22

3-
changedFiles="$(git clang-format --extensions cpp,h --style file --staged -q --diffstat -- ':!src/FreeRTOS' ':!src/libs')"
3+
minVersion="14.0.0"
4+
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+
changedFiles="$(git "$name" --extensions cpp,h --style file --staged -q --diffstat -- ':!src/FreeRTOS' ':!src/libs')"
421
git clang-format --extensions cpp,h --style file --staged -q -- ':!src/FreeRTOS' ':!src/libs'
522

623
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 1 | while read -r file; do

0 commit comments

Comments
 (0)