diff options
Diffstat (limited to 'kde-modules/kde-git-commit-hooks')
-rwxr-xr-x | kde-modules/kde-git-commit-hooks/clang-format.sh | 13 | ||||
-rw-r--r-- | kde-modules/kde-git-commit-hooks/pre-commit.in | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/kde-modules/kde-git-commit-hooks/clang-format.sh b/kde-modules/kde-git-commit-hooks/clang-format.sh new file mode 100755 index 00000000..d351e3cd --- /dev/null +++ b/kde-modules/kde-git-commit-hooks/clang-format.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# Based on okular/hooks/pre-commit, credits go to Albert Astals Cid + +readonly output=$(git clang-format -v --diff) + +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 --force # format the changed parts" +echo " git clang-format --diff # preview the changes done by the formatter" +exit 1 diff --git a/kde-modules/kde-git-commit-hooks/pre-commit.in b/kde-modules/kde-git-commit-hooks/pre-commit.in new file mode 100644 index 00000000..36cdfd5d --- /dev/null +++ b/kde-modules/kde-git-commit-hooks/pre-commit.in @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +${CLANG_FORMAT_SCRIPT} |