Whamcloud - gitweb
LU-1595 build: improve prepare-commit-msg git hook 27/13427/7
authorAndreas Dilger <andreas.dilger@intel.com>
Thu, 15 Jan 2015 21:50:20 +0000 (14:50 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 14 Jun 2016 03:49:34 +0000 (03:49 +0000)
Improve the Git prepare-commit-msg hook to still add the default
comment for Signed-off-by: and the Vim modeline, even if checkpatch.pl
isn't available.

Add a few more comments to the script.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: I253931c34ee64afa2d9cf160e675c779b32e9359
Reviewed-on: http://review.whamcloud.com/13427
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
contrib/git-hooks/prepare-commit-msg

index 9acb19e..c0cc1a5 100755 (executable)
@@ -13,9 +13,8 @@
 # It adds any checkpatch warnings/errors as commit comments, which
 # means that they can currently be ignored, but are at least visible.
 
-CHECKPATCH=contrib/scripts/checkpatch.pl
-CHECKPATCH_OPTS="--no-signoff --no-tree"
-[ -r "$CHECKPATCH" ] || exit 0
+CHECKPATCH=${CHECKPATCH:-contrib/scripts/checkpatch.pl}
+CHECKPATCH_OPTS=${CHECKPATCH_OPTS:-"--no-signoff --no-tree"}
 
 # If there are no comments in the commit, it is likely a rebase and
 # this shouldn't be adding new comments, or they appear in the commit.
@@ -23,12 +22,23 @@ grep -q "^#" "$1" || exit 0
 
 # Add a commented-out Signed-off-by: line.  This shouldn't be added in an
 # uncommented form, otherwise sanity checking for an emtpy commit fails.
+# The developer should uncomment it to include it in the commit message.
 SIGNOFF=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
 grep -qs "^$SIGNOFF" "$1" || echo "# $SIGNOFF" >> "$1"
 
 # Add the checkpatch.pl output as comments, but don't cause a commit error
-# yet, until there is more certainty that it is working correctly.
-echo "" >> "$1"
-echo "#" >> "$1"
-git diff --cached | $CHECKPATCH $CHECKPATCH_OPTS - | sed -e 's/^/# /' >> "$1"
+# yet, as there may be exceptions and it is better let a person decide.
+if [ -x "$CHECKPATCH" ]; then
+       echo "" >> "$1"
+       echo "#" >> "$1"
+       git diff --cached | $CHECKPATCH $CHECKPATCH_OPTS - | sed -e 's/^/# /' >> "$1"
+fi
+
+# Cause Vim to wrap text at 70 columns to match commit message style.
+# Adding a matching emacs modeline would be good, if I knew how to do that.
 echo "# vim:textwidth=70:" >> "$1"
+
+# Add these comments at the end
+# So that Vim does not pretend
+# The "echo" above is actually
+# A modeline for this file. Savvy?