2022-09-20 19:03:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-09-22 19:53:39 +00:00
|
|
|
CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
|
2022-09-20 19:03:44 +00:00
|
|
|
HAS_DIFFS=0
|
|
|
|
|
2022-09-22 19:53:39 +00:00
|
|
|
check_format_file() {
|
|
|
|
local item=$1
|
|
|
|
"$CLANG_FORMAT" --dry-run -Werror "$item" &>/dev/null
|
|
|
|
if [[ $? = 1 ]]; then
|
|
|
|
"${CLANG_FORMAT}" "${item}" | git diff --color=always --no-index "${item}" -
|
|
|
|
HAS_DIFFS=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-20 19:03:44 +00:00
|
|
|
check_format() {
|
|
|
|
local path=$1
|
2022-09-22 20:15:36 +00:00
|
|
|
find "$path" -type f -name "*" | while read item;
|
2022-09-20 19:03:44 +00:00
|
|
|
do
|
|
|
|
if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then
|
2022-09-22 20:33:16 +00:00
|
|
|
check_format_file "$item"
|
2022-09-20 19:03:44 +00:00
|
|
|
fi;
|
|
|
|
done;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_format "./apps"
|
|
|
|
check_format "./components"
|
|
|
|
|
|
|
|
if [[ $HAS_DIFFS -eq 1 ]]; then
|
|
|
|
echo "clang-format differences detected"
|
|
|
|
exit 1
|
|
|
|
fi;
|
|
|
|
|
|
|
|
exit 0
|