File indexing completed on 2024-05-05 16:04:58

0001 #!/usr/bin/env bash
0002 
0003 # Based on okular/hooks/pre-commit, credits go to Albert Astals Cid
0004 
0005 readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -v --diff)
0006 
0007 if [[ ! -f .clang-format ]]; then
0008     if [[ @HAS_CLANG_FORMAT_COMMAND_INCLUDED@ = TRUE ]]; then
0009         echo "ERROR: no .clang-format file found in repository root, abort format"
0010         echo "       run cmake for this repository to generate it"
0011     else
0012         echo "ERROR: no .clang-format file found in repository root, abort format"
0013         echo "Make sure the KDEClangFormat CMake module is included, which will copy the KDE .clang-format file during the CMake configuration."
0014         echo "Alternatively you can manually copy a .clang-format file to the repository root directory."
0015     fi
0016     exit 1
0017 fi
0018 if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi
0019 if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi
0020 
0021 echo "ERROR: You have unformatted changes, please format your files. You can do this using the following commands:"
0022 echo "       git clang-format --extensions 'cpp,h,hpp,c' --force # format the changed parts"
0023 echo "       git clang-format --extensions 'cpp,h,hpp,c' --diff # preview the changes done by the formatter"
0024 exit 1