From 222e877dabdb3a50592eaee5597f24750ec92e1f Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Tue, 26 Aug 2025 12:38:42 +0200 Subject: [PATCH] tools/checkpath.sh: check git commit format check git commit format: - line length less than 80 for commit title - affected subsystem (detecting colon in commit title ":") - Signed-off-by line - blacklist [VELAPLATO-*, WIP:] string in commit body Signed-off-by: raiden00pl --- tools/checkpatch.sh | 66 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index ae0ebc7c9d835..594a139ff2b2d 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -44,6 +44,9 @@ isort_warning_once=0 cvt2utf_warning_once=0 codespell_config_file_location_was_shown_once=0 +# links +COMMIT_URL="https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md" + usage() { echo "USAGE: ${0} [options] [list|-]" echo "" @@ -53,7 +56,7 @@ usage() { echo "-u encoding check with cvt2utf (install with: pip install cvt2utf)" echo "-r range check only (coupled with -p or -g)" echo "-p (default)" - echo "-m Change-Id check in commit message (coupled with -g)" + echo "-m Check commit message (coupled with -g)" echo "-g " echo "-f " echo "-x format supported files (only .py, requires: pip install black)" @@ -279,12 +282,61 @@ check_patch() { } check_msg() { - while read; do + signedoffby_found=0 + num_lines=0 + max_line_len=80 + min_num_lines=5 + + first=$(head -n1 <<< "$msg") + + # check for Merge line and remove from parsed string + if [[ $first == *Merge* ]]; then + msg="$(echo "$msg" | tail -n +2)" + first=$(head -n2 <<< "$msg") + fi + + while IFS= read -r REPLY; do if [[ $REPLY =~ ^Change-Id ]]; then echo "Remove Gerrit Change-ID's before submitting upstream" fail=1 fi - done + + if [[ $REPLY =~ ^VELAPLATO ]]; then + echo "Remove VELAPLATO before submitting upstream" + fail=1 + fi + + if [[ $REPLY =~ ^[Ww][Ii][Pp]: ]]; then + echo "Remove WIP before submitting upstream" + fail=1 + fi + + if [[ $REPLY =~ ^Signed-off-by ]]; then + signedoffby_found=1 + fi + + ((num_lines++)) + done <<< "$msg" + + if ! [[ $first =~ : ]]; then + echo "Commit subject missing colon (e.g. 'subsystem: msg')" + fail=1 + fi + + if (( ${#first} > $max_line_len )); then + echo "Commit subject too long > $max_line_len" + fail=1 + fi + + if ! [ $signedoffby_found == 1 ]; then + echo "Missing Signed-off-by" + fail=1 + fi + + if (( $num_lines < $min_num_lines && $signedoffby_found == 1 )); then + echo "Missing git commit message." + fail=1 + fi } check_commit() { @@ -349,4 +401,12 @@ for arg in $@; do $check $arg done + +if [ $fail == 1 ]; then + echo "Some checks failed. For contributing guidelines, see:" + echo " $COMMIT_URL" +else + echo "All checks pass." +fi + exit $fail