Skip to content

Commit c1a3909

Browse files
committed
tools/checkpath.sh check git commit format
check git commit format: - line length less than 72 for commit title and commit body - affected subsystem (detecting colon in commit title ":") - Signed-off-by line - blacklist [VELAPLATO-*, WIP:] string in commit body Signed-off-by: raiden00pl <[email protected]>
1 parent 2820600 commit c1a3909

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

tools/checkpatch.sh

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ isort_warning_once=0
4444
cvt2utf_warning_once=0
4545
codespell_config_file_location_was_shown_once=0
4646

47+
# links
48+
COMMIT_URL="https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md"
49+
4750
usage() {
4851
echo "USAGE: ${0} [options] [list|-]"
4952
echo ""
@@ -53,7 +56,7 @@ usage() {
5356
echo "-u encoding check with cvt2utf (install with: pip install cvt2utf)"
5457
echo "-r range check only (coupled with -p or -g)"
5558
echo "-p <patch file names> (default)"
56-
echo "-m Change-Id check in commit message (coupled with -g)"
59+
echo "-m Check commit message (coupled with -g)"
5760
echo "-g <commit list>"
5861
echo "-f <file list>"
5962
echo "-x format supported files (only .py, requires: pip install black)"
@@ -279,12 +282,64 @@ check_patch() {
279282
}
280283

281284
check_msg() {
285+
first=$(head -n1 <<< "$msg")
286+
signedoffby_found=0
287+
num_lines=0
288+
max_line_len=72
289+
min_num_lines=5
290+
282291
while read; do
283292
if [[ $REPLY =~ ^Change-Id ]]; then
284293
echo "Remove Gerrit Change-ID's before submitting upstream"
285294
fail=1
286295
fi
296+
297+
if [[ $REPLY =~ ^VELAPLATO ]]; then
298+
echo "Remove VELAPLATO before submitting upstream"
299+
fail=1
300+
fi
301+
302+
if [[ $REPLY =~ ^[Ww][Ii][Pp]: ]]; then
303+
echo "Remove WIP before submitting upstream"
304+
fail=1
305+
fi
306+
307+
if [[ $REPLY =~ ^[Ww][Ii][Pp]: ]]; then
308+
echo "Remove WIP before submitting upstream"
309+
fail=1
310+
fi
311+
312+
if [[ $REPLY =~ ^Signed-off-by ]]; then
313+
signedoffby_found=1
314+
fi
315+
316+
if (( ${#REPLY} > $max_line_len )); then
317+
echo "Commit message too long > $max_line_len"
318+
fail=1
319+
fi
320+
321+
((num_lines++))
287322
done
323+
324+
if ! [[ $first =~ : ]]; then
325+
echo "Commit subject missing colon (e.g. 'subsystem: msg')"
326+
fail=1
327+
fi
328+
329+
if (( ${#first} > $max_line_len )); then
330+
echo "Commit subject too long > $max_line_len"
331+
fail=1
332+
fi
333+
334+
if ! [ $signedoffby_found == 1 ]; then
335+
echo "Missing Signed-off-by"
336+
fail=1
337+
fi
338+
339+
if (( $num_lines < $min_num_lines && $signedoffby_found == 1 )); then
340+
echo "Missing git commit message."
341+
fail=1
342+
fi
288343
}
289344

290345
check_commit() {
@@ -349,4 +404,12 @@ for arg in $@; do
349404
$check $arg
350405
done
351406

407+
408+
if [ $fail == 1 ]; then
409+
echo "Some checks failed. For contributing guidelines, see:"
410+
echo " $COMMIT_URL"
411+
else
412+
echo "All checks pass."
413+
fi
414+
352415
exit $fail

0 commit comments

Comments
 (0)