Skip to content

Commit

Permalink
hook: Use clang-format with highest version
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed Feb 28, 2023
1 parent a3a1178 commit 3457040
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#!/bin/sh

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

name=""
version=""

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 | awk '{print $3}')"

if [ "$(printf '%s\n' "$curVersion" "$version" "$minVersion" | sort -V | tail -n 1)" = "$curVersion" ]; then
name="$curName"
version="$curVersion"
fi
done

if [ -z "$name" ]; then
echo "Could not find a suitable clang-format installation. Install clang-format with at least version $minVersion"
exit 1
fi

changedFiles="$(git "$name" --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs')"

echo "$changedFiles"

Expand Down

0 comments on commit 3457040

Please sign in to comment.