1- #! /bin/sh
1+ #! /bin/bash
22#
33# An example hook script to check the commit log message.
44# Called by "git commit" with one argument, the name of the file
@@ -59,7 +59,8 @@ and keeping a clean history, please see:
5959 2. http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
6060 3. https://www.reviewboard.org/docs/codebase/dev/git/clean-commits/
6161
62- And for funny examples of what not to do, see: http://whatthecommit.com
62+ And for funny examples of what not to do, see: http://whatthecommit.com and
63+ http://stopwritingramblingcommitmessages.com
6364EOF
6465
6566}
@@ -77,7 +78,8 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
7778# Check that the first line of the commit starts with a
7879# capitalized letter.
7980if ! (head -n 1 $1 | grep ' ^[A-Z]' & > /dev/null ); then
80- echo >&2 " First word of commit message must be a capitalized imperative verb.\n"
81+ echo >&2 " First word of commit message must be a capitalized imperative verb."
82+ echo " "
8183 let status=1
8284fi
8385
@@ -89,23 +91,28 @@ cat $1 | \
8991 nchars=$( wc -c <<< $line )
9092 if [[ " $ln " -eq " 1" ]]; then
9193 if [[ " $nchars " -gt " 51" ]]; then
92- echo >&2 " First line of commit message too long ($nchars > 50 chars)\n"
94+ echo >&2 " First line of commit message too long ($nchars > 50 chars)"
95+ echo " "
9396 let status=1
9497 fi
9598 elif [[ " $ln " -eq " 2" ]]; then
9699 if [[ " $nchars " -gt " 1" ]] && ! grep ' ^#' <<< " $line" > /dev/null; then
97- echo >&2 " Second line of commit message not blank\n"
100+ echo >&2 " Second line of commit message not blank"
101+ echo " "
98102 let status=1
99103 fi
100104 else
101105 if [[ " $nchars " -gt " 72" ]]; then
102- echo >&2 " Line $ln of commit message too long ($nchars > 72 chars)\n"
106+ echo >&2 " Line $ln of commit message too long ($nchars > 72 chars)"
107+ echo " "
103108 let status=1
104109 fi
105110 fi
106111 done
107112
108- if [[ $status != 0 ]]; then
109- error_message
110- exit 1
113+ if [[ $status = 0 ]]; then
114+ exit 0
111115fi
116+
117+ error_message
118+ exit 1
0 commit comments