Whamcloud - gitweb
LU-3963 libcfs: convert DT objects atomic primitives
[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=contrib/scripts/checkpatch.pl
17 CHECKPATCH_OPTS="--no-signoff --no-tree"
18 [ -r "$CHECKPATCH" ] || exit 0
19
20 # If there are no comments in the commit, it is likely a rebase and
21 # this shouldn't be adding new comments, or they appear in the commit.
22 grep -q "^#" "$1" || exit 0
23
24 # Add a commented-out Signed-off-by: line.  This shouldn't be added in an
25 # uncommented form, otherwise sanity checking for an emtpy commit fails.
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, until there is more certainty that it is working correctly.
31 echo "" >> "$1"
32 echo "#" >> "$1"
33 git diff --cached | $CHECKPATCH $CHECKPATCH_OPTS - | sed -e 's/^/# /' >> "$1"
34 echo "# vim:textwidth=70:" >> "$1"