diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-08-14 20:24:10 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-08-14 20:24:10 +0300 |
commit | 1dc163c06639d6c225b25c9dd2955b21bbb706d3 (patch) | |
tree | 5a379a32304aca490df87211d0425220eea69643 /hooks | |
parent | Update CMakeLists to use Qt6 (diff) | |
download | rekonq-1dc163c06639d6c225b25c9dd2955b21bbb706d3.tar.xz |
pre-commit hook: Add clang-format check
Diffstat (limited to 'hooks')
-rw-r--r-- | hooks/README.md | 3 | ||||
-rwxr-xr-x | hooks/clang-format.sh | 24 | ||||
-rwxr-xr-x | hooks/pre-commit | 3 |
3 files changed, 30 insertions, 0 deletions
diff --git a/hooks/README.md b/hooks/README.md new file mode 100644 index 00000000..d030e315 --- /dev/null +++ b/hooks/README.md @@ -0,0 +1,3 @@ +The commit hook has been copied from the kmail source code. + +To install, symlink the hooks into ``.git/hooks`` diff --git a/hooks/clang-format.sh b/hooks/clang-format.sh new file mode 100755 index 00000000..716a80ff --- /dev/null +++ b/hooks/clang-format.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Based on okular/hooks/pre-commit, credits go to Albert Astals Cid + +readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -v --diff) + +if [[ ! -f .clang-format ]]; then + if [[ TRUE = TRUE ]]; then + echo "ERROR: no .clang-format file found in repository root, abort format" + echo " run cmake for this repository to generate it" + else + echo "ERROR: no .clang-format file found in repository root, abort format" + echo "Make sure the KDEClangFormat CMake module is included, which will copy the KDE .clang-format file during the CMake configuration." + echo "Alternatively you can manually copy a .clang-format file to the repository root directory." + fi + exit 1 +fi +if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi +if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi + +echo "ERROR: You have unformatted changes, please format your files. You can do this using the following commands:" +echo " git clang-format --extensions 'cpp,h,hpp,c' --force # format the changed parts" +echo " git clang-format --extensions 'cpp,h,hpp,c' --diff # preview the changes done by the formatter" +exit 1 diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 00000000..aa7cbe8a --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./hooks/clang-format.sh |