X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=contrib%2Fgit-hooks%2Fprepare-commit-msg;h=e4a94c9bede7296f86affdc3989f3ba588fc2ea9;hb=b5c4f0305323a44c38357420e1ee84dd343f4875;hp=9acb19ee12e72ad88aca32a5985cfee963c32158;hpb=25c93758d6b1136d268fe3fcc1c4979c17463c0b;p=fs%2Flustre-release.git diff --git a/contrib/git-hooks/prepare-commit-msg b/contrib/git-hooks/prepare-commit-msg index 9acb19e..e4a94c9 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,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?