Fix pre-commit to only check staged files

This commit is contained in:
Alexander Kremer
2022-11-11 12:38:55 +00:00
committed by Michael Legleux
parent a47bf2e8fe
commit b13c44eb12

View File

@@ -2,14 +2,16 @@
exec 1>&2
# format all relevant sources
find src unittests -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 clang-format -i
# paths to check and re-format
sources="src unittests"
formatter="clang-format -i"
# check how many lines differ
lines=$(git diff src unittests | wc -l)
first=$(git diff $sources)
find $sources -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 $formatter
second=$(git diff $sources)
changes=$(diff <(echo "$first") <(echo "$second") | wc -l)
# check if there is any updated files
if [ "$lines" != "0" ]; then
if [ "$changes" != "0" ]; then
cat <<\EOF
WARNING