Skip to content

Commit

Permalink
hook: Use clang-format with highest version
Browse files Browse the repository at this point in the history
Also fixes some inconsistencies.
  • Loading branch information
FintasticMan committed Jan 12, 2023
1 parent dd03238 commit 8d2477c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#!/bin/sh

git clang-format --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs'
name=""
version="14.0.0"

git diff --name-only --diff-filter=ACMR | while read -r file
do
for file in $(find $(echo "$PATH" | sed 's/:/ /g') -type f -executable -name 'git-clang-format*'); do
cur_name="$(basename "$file" | sed 's/^git-//')"
cur_version="$("$cur_name" --version | awk '{print $3}')"

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

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

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

echo "$changed_files"

echo "$changed_files" | tail -n +2 | while read -r file; do
git add -- "$file"
done

0 comments on commit 8d2477c

Please sign in to comment.