Whamcloud - gitweb
LU-7860 ldlm: revert part of commit 657bbc49
[fs/lustre-release.git] / contrib / git-hooks / prepare-commit-msg
1 #!/bin/bash
2 #
3 # A Git hook script to prepare the commit log message.  Install into
4 # lustre/.git/hooks/prepare-commit-msg to enable for Lustre commits.
5 #
6 # Called by git-commit with the name of the file that has the
7 # commit message, followed by the description of the commit
8 # message's source.  The hook's purpose is to edit the commit
9 # message file.  If the hook fails with a non-zero status,
10 # the commit is aborted.
11 #
12 # Commit hook to check the patch against the Lustre coding style.
13 # It adds any checkpatch warnings/errors as commit comments, which
14 # means that they can currently be ignored, but are at least visible.
15
16 CHECKPATCH=${CHECKPATCH:-contrib/scripts/checkpatch.pl}
17 CHECKPATCH_OPTS=${CHECKPATCH_OPTS:-"--no-signoff --no-tree"}
18
19 # If there are no comments in the commit, it is likely a rebase and
20 # this shouldn't be adding new comments, or they appear in the commit.
21 grep -q "^#" "$1" || exit 0
22
23 # Add a commented-out Signed-off-by: line.  This shouldn't be added in an
24 # uncommented form, otherwise sanity checking for an emtpy commit fails.
25 # The developer should uncomment it to include it in the commit message.
26 SIGNOFF=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
27 grep -qs "^$SIGNOFF" "$1" || echo "# $SIGNOFF" >> "$1"
28
29 # Add the checkpatch.pl output as comments, but don't cause a commit error
30 # yet, as there may be exceptions and it is better let a person decide.
31 if [ -x "$CHECKPATCH" ]; then
32         echo "" >> "$1"
33         echo "#" >> "$1"
34         [ -d ".git/rebase-apply" -o -d ".git/rebase-merge" ] &&
35                 DIFFOPT="HEAD" || DIFFOPT="--cached"
36         git diff $DIFFOPT | $CHECKPATCH $CHECKPATCH_OPTS - |
37                 sed -e 's/^/# /' >> "$1"
38 fi
39
40 # Cause Vim to wrap text at 70 columns to match commit message style.
41 # Adding a matching emacs modeline would be good, if I knew how to do that.
42 echo "# vim:textwidth=70:" >> "$1"
43
44 # Add these comments at the end
45 # So that Vim does not pretend
46 # The "echo" above is actually
47 # A modeline for this file. Savvy?