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