Extras: Add a checkpatch git pre-commit hook
authorChristian Babeux <christian.babeux@efficios.com>
Mon, 7 Jan 2013 22:12:42 +0000 (17:12 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 10 Jan 2013 17:52:53 +0000 (12:52 -0500)
This commit add the checkpatch-hook script that can be installed in git
hooks folder in order to detect style issue before commiting any staged
changes.

The .checkpatch.conf file contains the appropriate options conforming to
the coding style used in the lttng-tools tree.

Also included in this commit is an install script to automatically
install the hook in the git local repo.

To override the pre-commit hook check, one can use the
`git commit --no-verify` command.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
.gitignore
extras/.checkpatch.conf [new file with mode: 0644]
extras/checkpatch-hook [new file with mode: 0755]
extras/install-checkpatch-hook [new file with mode: 0755]

index afc97b6eb6d8ab6d0b0914ef1e232e2f0f29346f..aa794ae1fad144aaacde47384a408102b6ca7e8b 100644 (file)
@@ -46,6 +46,8 @@ extras/bindings/swig/python/lttng.i
 extras/bindings/swig/python/lttng.py
 extras/bindings/swig/python/lttng_wrap.c
 
+.checkpatch.conf
+
 # Tests
 test_sessions
 test_kernel_data_trace
diff --git a/extras/.checkpatch.conf b/extras/.checkpatch.conf
new file mode 100644 (file)
index 0000000..936f435
--- /dev/null
@@ -0,0 +1,7 @@
+# Not a kernel tree
+--no-tree
+
+# Ignore braces {} are not necessary for single statement blocks warning.
+# We enforce usage of {} even on single statement blocks.
+# See CodingStyles for more information.
+--ignore BRACES_SINGLE_STMT
diff --git a/extras/checkpatch-hook b/extras/checkpatch-hook
new file mode 100755 (executable)
index 0000000..686815b
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# To enable this hook, run the "install-checkpatch-hook" script.
+
+CHECKPATCH="extras/checkpatch.pl"
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+       against=HEAD
+else
+       # Initial commit: diff against an empty tree object
+       against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+git diff --cached $against -- | $CHECKPATCH --no-signoff -
diff --git a/extras/install-checkpatch-hook b/extras/install-checkpatch-hook
new file mode 100755 (executable)
index 0000000..9f0e985
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Install the checkpatch pre-commit hook.
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+PRECOMMIT_HOOK="../.git/hooks/pre-commit"
+PRECOMMIT_SCRIPT="checkpatch-hook"
+CHECKPATCH_CONF=".checkpatch.conf"
+
+if [ -f $PRECOMMIT_HOOK ];
+then
+   echo "File $PRECOMMIT_HOOK already exists. Aborting."
+   exit 1
+else
+    ln -s $DIR/$PRECOMMIT_SCRIPT $PRECOMMIT_HOOK
+fi
+
+if [ -f ../$CHECKPATCH_CONF ];
+then
+   echo "File ../$CHECKPATCH_CONF already exists. Aborting."
+   exit 1
+else
+    ln -s $DIR/$CHECKPATCH_CONF ../$CHECKPATCH_CONF
+fi
+
+echo "Checkpatch pre-commit hook successfully installed!"
This page took 0.039368 seconds and 4 git commands to generate.