From b1c8f737c8bbe862930cc0f174bd478ba42f7ffe Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 15 Jan 2015 14:50:20 -0700 Subject: [PATCH] LU-1595 build: improve prepare-commit-msg git hook 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 Change-Id: I253931c34ee64afa2d9cf160e675c779b32e9359 Reviewed-on: http://review.whamcloud.com/13427 Reviewed-by: Dmitry Eremin Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- contrib/git-hooks/prepare-commit-msg | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/contrib/git-hooks/prepare-commit-msg b/contrib/git-hooks/prepare-commit-msg index 9acb19e..c0cc1a5 100755 --- a/contrib/git-hooks/prepare-commit-msg +++ b/contrib/git-hooks/prepare-commit-msg @@ -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? -- 1.8.3.1