diff options
author | Jan Holesovsky <kendy@suse.cz> | 2009-03-25 11:51:31 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2009-03-25 11:54:06 +0100 |
commit | 5d8ae53ca0c61d50046e62f863308bcbd036cfcf (patch) | |
tree | b480fec660a69a8a1d4c948329fefe03df857f4b /git-hooks | |
parent | 13507463527d72fdbd610d65e938d8dc93ef1404 (diff) |
More improvements in the commit-msg hook.
Hopefully it's not getting too intrusive ;-)
Diffstat (limited to 'git-hooks')
-rwxr-xr-x | git-hooks/commit-msg | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index 782ead537..75bbeb074 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -14,34 +14,57 @@ # This example catches duplicate Signed-off-by lines. +abort() { + cp $1 $1.save + cat >&2 <<EOF +Commit aborted, your commit message was saved as '$1.save'. + +Reason: $2 + +EOF + exit 1 +} + test "" = "$(grep '^Signed-off-by: ' "$1" | sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Commit aborted: Duplicate Signed-off-by lines. - exit 1 + abort "$1" "Duplicate Signed-off-by lines." } # Abort the commit if the message is the same as the one prepared by # the prepare-commit-msg hook if [ -f "$1.prepare" ] ; then - diff "$1" "$1.prepare" > /dev/null 2>/dev/null && { - echo >&2 Commit aborted: No change in the commit message. - exit 1 - } + diff "$1" "$1.prepare" > /dev/null 2>/dev/null && \ + abort "$1" "No change in the commit message." fi # Check that the first line exists, and is not an asterisk if [ -z "`head -n 1 $1 | grep -v '^[ \t]*\*'`" ] ; then - echo >&2 Commit aborted: Please provide the general description on the first line. - exit 1 + abort "$1" "Please provide the general description on the first line." +fi + +# ...and that it is not too long + +if [ "`head -n 1 $1 | wc -c`" -gt 79 ] ; then + abort "$1" "The first line is too long, please try to fit into 79 characters." +fi + +# ...and that it does not continue on the second line +if [ -n "`head -n 2 $1 | tail -n 1 | sed 's/^#.*//'`" ] ; then + abort "$1" "The second line is not empty - maybe the first line continues there?" fi # Check that the message is not a ChangeLog-like one if [ -n "`head -n 1 $1 | grep '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.*<.*@.*>'`" ] ; then - echo >&2 Commit aborted: The commit message looks ChangeLog, please use the git form. - exit 1 + abort "$1" "The commit message looks like ChangeLog, please use the git form." +fi + +# Check for whitespace in front of *'s + +if [ -n "`grep '^[[:space:]]\+\*.*:' $1`" -a -z "`grep '^\*' $1`" ] ; then + abort "$1" "Please don't use whitespace in front of '* file: Description.' entries." fi exit 0 |