@@ -110,6 +110,9 @@ validate_commit_message() {
110
110
# reset warnings
111
111
WARNINGS=()
112
112
113
+ # capture the subject
114
+ COMMIT_SUBJECT=${COMMIT_MSG_LINES[0]}
115
+
113
116
# if the commit is empty there's nothing to validate, we can return here
114
117
COMMIT_MSG_STR=" ${COMMIT_MSG_LINES[*]} "
115
118
test -n " ${COMMIT_MSG_STR[*]// } " || return ;
@@ -123,19 +126,19 @@ validate_commit_message() {
123
126
# 2. Limit the subject line to 50 characters
124
127
# ------------------------------------------------------------------------------
125
128
126
- test " ${# COMMIT_MSG_LINES[0] } " -le 50
127
- test $? -eq 0 || add_warning 1 " Limit the subject line to 50 characters (${# COMMIT_MSG_LINES[0] } chars)"
129
+ test " ${# COMMIT_SUBJECT } " -le 50
130
+ test $? -eq 0 || add_warning 1 " Limit the subject line to 50 characters (${# COMMIT_SUBJECT } chars)"
128
131
129
132
# 3. Capitalize the subject line
130
133
# ------------------------------------------------------------------------------
131
134
132
- [[ ${COMMIT_MSG_LINES[0] } =~ ^[[:blank:]]* ([[:upper:]]{1}[[:lower:]]* | [[:digit:]]+)([[:blank:]]| [[:punct:]]| $) ]]
135
+ [[ ${COMMIT_SUBJECT } =~ ^[[:blank:]]* ([[:upper:]]{1}[[:lower:]]* | [[:digit:]]+)([[:blank:]]| [[:punct:]]| $) ]]
133
136
test $? -eq 0 || add_warning 1 " Capitalize the subject line"
134
137
135
138
# 4. Do not end the subject line with a period
136
139
# ------------------------------------------------------------------------------
137
140
138
- [[ ${COMMIT_MSG_LINES[0] } =~ [^\. ]$ ]]
141
+ [[ ${COMMIT_SUBJECT } =~ [^\. ]$ ]]
139
142
test $? -eq 0 || add_warning 1 " Do not end the subject line with a period"
140
143
141
144
# 5. Use the imperative mood in the subject line
@@ -174,7 +177,7 @@ validate_commit_message() {
174
177
shopt -s nocasematch
175
178
176
179
for BLACKLISTED_WORD in " ${IMPERATIVE_MOOD_BLACKLIST[@]} " ; do
177
- [[ ${COMMIT_MSG_LINES[0] } =~ $BLACKLISTED_WORD ]]
180
+ [[ ${COMMIT_SUBJECT } =~ $BLACKLISTED_WORD ]]
178
181
test $? -eq 0 && add_warning 1 " Use the imperative mood in the subject line, e.g 'fix' not 'fixes'" && break
179
182
done
180
183
@@ -200,14 +203,14 @@ validate_commit_message() {
200
203
# 8. Do no write single worded commits
201
204
# ------------------------------------------------------------------------------
202
205
203
- COMMIT_SUBJECT_WORDS=(${COMMIT_MSG_LINES[0] } )
206
+ COMMIT_SUBJECT_WORDS=(${COMMIT_SUBJECT } )
204
207
test " ${# COMMIT_SUBJECT_WORDS[@]} " -gt 1
205
208
test $? -eq 0 || add_warning 1 " Do no write single worded commits"
206
209
207
210
# 9. Do not start the subject line with whitespace
208
211
# ------------------------------------------------------------------------------
209
212
210
- [[ ${COMMIT_MSG_LINES[0] } =~ ^[[:blank:]]+ ]]
213
+ [[ ${COMMIT_SUBJECT } =~ ^[[:blank:]]+ ]]
211
214
test $? -eq 1 || add_warning 1 " Do not start the subject line with whitespace"
212
215
}
213
216
0 commit comments