summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@qt.io>2018-06-24 11:37:58 +0200
committerFrederik Gladhorn <frederik.gladhorn@qt.io>2019-09-19 06:36:15 +0000
commit3b937032f51c75b3f517e02b1db670884a8dc103 (patch)
tree81ff2bc7f11ea95472c9534c896db7a4f94ca78c
parent37df2fd634feac3458c19b8a37a44a36f8e3a72f (diff)
Add clang-format-pre-commit hook
Change-Id: Iafa2ce4ca485122e44e5b143af68823793dd4b85 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rwxr-xr-xgit-hooks/clang-format-pre-commit29
1 files changed, 29 insertions, 0 deletions
diff --git a/git-hooks/clang-format-pre-commit b/git-hooks/clang-format-pre-commit
new file mode 100755
index 0000000..051c6dd
--- /dev/null
+++ b/git-hooks/clang-format-pre-commit
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 2018 The Qt Company Ltd.
+# Contact: http://www.qt.io/licensing/
+#
+# You may use this file under the terms of the 3-clause BSD license.
+# See the file LICENSE from this package for details.
+#
+
+# Usage: in every repository you want to have checked:
+# cd .git/hooks
+# ln -s /path/to/git_pre_commit_hook pre-commit
+#
+
+CLANG_FORMAT=`which git-clang-format`
+if test -n "$CLANG_FORMAT"
+ echo "Please install clang-format and make sure git-clang-format is in the path."
+ exit 0
+fi
+
+CLANG_FORMAT_DIFF=`git clang-format -q --diff`
+if test -n "$CLANG_FORMAT_DIFF"; then
+ echo "clang-format output:"
+ echo "$CLANG_FORMAT_DIFF"
+ echo "clang-format detected change in format, please run:"
+ echo " git clang-format"
+ echo "and amend the change."
+ exit 1
+fi
+