File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33# Confirms that a commit message does not exceed 72 characters for any line and suggests one if it does.
44#
55
6- readonly MAX_LINE_LENGTH=72
6+ readonly MAX_SUBJECT_LENGTH=50
7+ readonly MAX_BODY_LENGTH=72
78readonly VERSION=" commit-msg 0.1.0"
89
910while getopts " :v-:" opt; do
@@ -32,18 +33,24 @@ OPTIND=1
3233
3334corrected=' '
3435ok=true
36+ line_count=0
3537while IFS=' ' read -r line || [[ -n " $line " ]]; do
36- if (( "${# line} " > "$MAX_LINE_LENGTH " )) && [[ " $line " != \# * ]] ; then
37- corrected+=" $( echo " $line " | fold -w " $MAX_LINE_LENGTH " -s) \n"
38+ if (( "$line_count " == 0 )) && (( "${# line} " > "$MAX_SUBJECT_LENGTH " )) && [[ " $line " != \# * ]]; then
39+ echo " error: the subject must be less than or equal to $MAX_SUBJECT_LENGTH characters" >&2
40+ exit 1
41+ elif (( "${# line} " > "$MAX_BODY_LENGTH " )) && [[ " $line " != \# * ]]; then
42+ corrected+=" $( echo " $line " | fold -w " $MAX_BODY_LENGTH " -s) \n"
3843 ok=false
44+ (( line_count++ ))
3945 elif [[ " $line " != \# * ]]; then
4046 corrected+=" $line \n"
47+ (( line_count++ ))
4148 fi
4249done < " $1 "
4350
4451if [[ " $ok " == false ]]; then
4552 echo " error: maximum line length exceeded" >&2
46- echo " error: all lines must be less than or equal to $MAX_LINE_LENGTH characters" >&2
53+ echo " error: all subject lines must be less than or equal to $MAX_BODY_LENGTH characters" >&2
4754 echo " error: use --no-verify to skip this check next time"
4855 echo " consider:" >&2
4956 echo " $( echo -e " $corrected " ) " >&2 # the nested echo is a cheap hack to remove multiple trailing new lines
You can’t perform that action at this time.
0 commit comments