[libcamera-devel] [PATCH v3 6/6] checkstyle: Add a pre-commit hook script

Nicolas Dufresne nicolas at ndufresne.ca
Sat Jan 18 04:54:48 CET 2020


From: Nicolas Dufresne <nicolas.dufresne at collabora.com>

This adds support for pre-commit hook workflow. In pre-commit hook we
check the style on the changes currently staged or the combination
of the index and the last commit if "git commit --amend" is being used.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
---
 utils/hooks/pre-commit | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 utils/hooks/pre-commit

diff --git a/utils/hooks/pre-commit b/utils/hooks/pre-commit
new file mode 100755
index 0000000..7a5554d
--- /dev/null
+++ b/utils/hooks/pre-commit
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Execute the checkstyle script after committing any code. This allows the
+# commit to succeed, but ensures that the developer is aware of any potential
+# issues immediately, and can resolve them and fix rapidly with:
+#   git commit --amend
+#
+# To utilise this hook, install this file with:
+#   cp utils/hooks/post-commit .git/hooks/post-commit
+
+args="--staged"
+if ps -ocommand= -p $PPID | grep -- "--amend"
+then
+   args="--amend"
+fi
+
+./utils/checkstyle.py $args
-- 
2.24.1



More information about the libcamera-devel mailing list