Whamcloud - gitweb
LU-11568 ldlm: Remove use of SLAB_DESTROY_BY_RCU for ldlm lock slab
[fs/lustre-release.git] / contrib / git-hooks / prepare-commit-msg
index 9acb19e..e4a94c9 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,26 @@ 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"
+       [ -d ".git/rebase-apply" -o -d ".git/rebase-merge" ] &&
+               DIFFOPT="HEAD" || DIFFOPT="--cached"
+       git diff $DIFFOPT | $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?