2020-10-06 19:57:33 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
project_folder=$(git rev-parse --show-toplevel)
|
|
|
|
if git rev-parse --verify HEAD >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
against=HEAD
|
|
|
|
else
|
|
|
|
# Initial commit: diff against an empty tree object
|
|
|
|
against=$(git hash-object -t tree /dev/null)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Redirect output to stderr.
|
|
|
|
exec 1>&2
|
|
|
|
|
|
|
|
tmpdir=$(mktemp -d repo-XXXXXXXX)
|
|
|
|
trap "rm -rf $tmpdir" EXIT INT
|
|
|
|
|
2021-02-16 18:22:59 +08:00
|
|
|
modified_files=$(git diff --cached --name-only --diff-filter=AM $against | sed -nE "/.*\.(cpp|cc|cxx|c|h|hpp)$/p")
|
2022-03-03 00:22:37 +08:00
|
|
|
FAIL=0
|
2020-10-06 19:57:33 +08:00
|
|
|
for file in $modified_files; do
|
|
|
|
echo "Checking $file..."
|
|
|
|
|
|
|
|
cp $project_folder/.clang-format $project_folder/.clang-tidy $tmpdir
|
|
|
|
|
|
|
|
git checkout-index --prefix="$tmpdir/" -- $file
|
|
|
|
|
2022-03-03 00:22:37 +08:00
|
|
|
# Do not break header checker
|
2021-10-07 20:51:30 +08:00
|
|
|
echo "Running header checker..."
|
2022-01-13 16:18:27 +08:00
|
|
|
$project_folder/tools/header-checker.py $tmpdir/$file $file --amend-year
|
2022-03-03 00:22:37 +08:00
|
|
|
CODE=$?
|
|
|
|
if [ $CODE -ne 0 ]; then
|
|
|
|
FAIL=1
|
|
|
|
fi
|
2020-10-06 19:57:33 +08:00
|
|
|
done;
|
|
|
|
|
2022-03-09 22:53:33 +08:00
|
|
|
return ${FAIL}
|