Skip to content

Commit 0503248

Browse files
committed
hook: Find correct clang-format version better
1 parent c634a4e commit 0503248

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

hooks/pre-commit

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/bin/sh
22

3+
name="clang-format"
4+
5+
if [ -z "$(command -v "git-$name")" ]; then
6+
name="$(basename -a $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'git-clang-format*') | sort | tail -n 1 | sed 's/^git-//')"
7+
fi
8+
39
minVersion="14.0.0"
410

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)"
11+
for file in $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'clang-format*'); do
12+
curBin="$file"
13+
curVersion="$("$curBin" --version | cut -d ' ' -f 3)"
814

915
if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then
10-
name="$curName"
16+
bin="$curBin"
1117
version="$curVersion"
1218
fi
1319
done
1420

15-
if [ -z "$name" ]; then
21+
if [ -z "$name" ] || [ -z "$bin" ]; then
1622
echo "Could not find a suitable clang-format installation. Install clang-format that includes the git-clang-format script, with at least version $minVersion"
1723
exit 1
1824
fi
1925

20-
args='-q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs'
26+
args="--binary $bin -q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs"
2127

2228
changedFiles="$(git "$name" --diffstat $args)"
2329
git "$name" $args

0 commit comments

Comments
 (0)