#!/bin/bash

find src include -iname \*.h -o -iname \*.c -o -iname \*.cpp -o -iname \*.hpp -o -iname \*.tpp\
    | xargs clang-format -style=file -i -fallback-style=none

git diff > clang_format.patch

# Delete if 0 size
if [ ! -s clang_format.patch ]
then
    rm clang_format.patch
    exit 0
fi

echo "The code is not formatted according to clang-format"
echo "Here is the diff:"
echo cat clang_format.patch
echo ""
cat clang_format.patch
echo ""
echo "Please run the following command in the root directory:"
echo "find src include -iname \*.h -o -iname \*.c -o -iname \*.cpp -o -iname \*.hpp -o -iname \*.tpp | xargs clang-format -style=file -i -fallback-style=none"

exit 1
