2023-01-03 16:25:55 +00:00
#!/bin/sh
2021-05-01 17:36:27 +00:00
2023-11-16 11:13:29 +00:00
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
2023-01-09 22:46:53 +00:00
minVersion="14.0.0"
2021-05-03 11:12:33 +00:00
2023-11-16 11:13:29 +00:00
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)"
2023-01-09 22:46:53 +00:00
if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then
2023-11-16 11:13:29 +00:00
bin="$curBin"
2023-01-09 22:46:53 +00:00
version="$curVersion"
fi
done
2023-11-16 11:13:29 +00:00
if [ -z "$name" ] || [ -z "$bin" ]; then
2023-01-09 22:46:53 +00:00
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
2023-11-16 11:13:29 +00:00
args="--binary $bin -q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs"
2023-01-09 22:46:53 +00:00
changedFiles="$(git "$name" --diffstat $args)"
git "$name" $args
echo "$changedFiles" | head -n -1 | cut -d ' ' -f 2 | while read -r file; do
2023-01-03 16:25:55 +00:00
git add -- "$file"
2021-04-18 16:20:16 +00:00
done