aboutsummaryrefslogtreecommitdiff
path: root/kde-modules/kde-git-commit-hooks/clang-format.sh
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-01-11 20:39:06 +0100
committerDavid Faure <faure@kde.org>2021-01-16 08:50:13 +0000
commit45edd1b17051def13c157cba3b01fac53364149c (patch)
treeec6644d3b24cf272ae1a6e87e9720fe409de2985 /kde-modules/kde-git-commit-hooks/clang-format.sh
parentb7affc18e5dad21fe29451cd9ecff54e40e42d79 (diff)
downloadextra-cmake-modules-45edd1b17051def13c157cba3b01fac53364149c.tar.gz
extra-cmake-modules-45edd1b17051def13c157cba3b01fac53364149c.tar.bz2
Add cmake function to configure git pre-commit hooks
This will allow us to force QS checks before the developer commits a change. Currently only clang-format is supported, but as on #plasma and https://phabricator.kde.org/T11214 discussed we might want to add different formatters. By making the checks configurable we are flexible and can easily extend it.
Diffstat (limited to 'kde-modules/kde-git-commit-hooks/clang-format.sh')
-rwxr-xr-xkde-modules/kde-git-commit-hooks/clang-format.sh13
1 files changed, 13 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