aboutsummaryrefslogtreecommitdiffstats
path: root/hooks/pre-commit
diff options
context:
space:
mode:
authorFintasticMan <finlay.neon.kid@gmail.com>2023-11-16 12:13:29 +0100
committerFintasticMan <finlay.neon.kid@gmail.com>2024-01-12 14:42:53 +0100
commit0503248a258d64e195c8ecbf701ea36ba1e642cb (patch)
treef808feaa54b73c2399939ab59fbf6988c738ed3d /hooks/pre-commit
parentc634a4e3b44f0d1b020be2bbb52ac57fb4f8772d (diff)
hook: Find correct clang-format version better
Diffstat (limited to 'hooks/pre-commit')
-rwxr-xr-xhooks/pre-commit18
1 files changed, 12 insertions, 6 deletions
diff --git a/hooks/pre-commit b/hooks/pre-commit
index e03b4217..60a01e34 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -1,23 +1,29 @@
#!/bin/sh
+name="clang-format"
+
+if [ -z "$(command -v "git-$name")" ]; then
+ name="$(basename -a $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'git-clang-format*') | sort | tail -n 1 | sed 's/^git-//')"
+fi
+
minVersion="14.0.0"
-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)"
+for file in $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'clang-format*'); do
+ curBin="$file"
+ curVersion="$("$curBin" --version | cut -d ' ' -f 3)"
if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then
- name="$curName"
+ bin="$curBin"
version="$curVersion"
fi
done
-if [ -z "$name" ]; then
+if [ -z "$name" ] || [ -z "$bin" ]; 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'
+args="--binary $bin -q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs"
changedFiles="$(git "$name" --diffstat $args)"
git "$name" $args