scripts: fix commit check for empty list
[dpdk.git] / scripts / check-git-log.sh
index b7ea1be..7ea4458 100755 (executable)
@@ -49,27 +49,28 @@ fi
 
 range=${1:-origin/master..}
 
+commits=$(git log --format='%h' $range)
 headlines=$(git log --format='%s' $range)
 bodylines=$(git log --format='%b' $range)
 tags=$(git log --format='%b' $range | grep -i -e 'by *:' -e 'fix.*:')
 fixes=$(git log --format='%h %s' $range | grep -i ': *fix' | cut -d' ' -f1)
 
 # check headline format (spacing, no punctuation, no code)
-bad=$(echo "$headlines" | grep \
+bad=$(echo "$headlines" | grep --color=always \
        -e '    ' \
        -e '^ ' \
        -e ' $' \
        -e '\.$' \
        -e '[,;!?&|]' \
        -e ':.*_' \
-       -e '^[^:]*$' \
+       -e '^[^:]\+$' \
        -e ':[^ ]' \
        -e ' :' \
        | sed 's,^,\t,')
 [ -z "$bad" ] || printf "Wrong headline format:\n$bad\n"
 
 # check headline label for common typos
-bad=$(echo "$headlines" | grep \
+bad=$(echo "$headlines" | grep --color=always \
        -e '^example[:/]' \
        -e '^apps/' \
        -e '^testpmd' \
@@ -79,14 +80,14 @@ bad=$(echo "$headlines" | grep \
 [ -z "$bad" ] || printf "Wrong headline label:\n$bad\n"
 
 # check headline lowercase for first words
-bad=$(echo "$headlines" | grep \
+bad=$(echo "$headlines" | grep --color=always \
        -e '^.*[A-Z].*:' \
        -e ': *[A-Z]' \
        | sed 's,^,\t,')
 [ -z "$bad" ] || printf "Wrong headline uppercase:\n$bad\n"
 
 # check headline uppercase (Rx/Tx, VF, L2, MAC, Linux, ARM...)
-bad=$(echo "$headlines" | grep -E \
+bad=$(echo "$headlines" | grep -E --color=always \
        -e '\<(rx|tx|RX|TX)\>' \
        -e '\<[pv]f\>' \
        -e '\<l[234]\>' \
@@ -111,9 +112,16 @@ bad=$(echo "$headlines" | awk 'length>60 {print}' | sed 's,^,\t,')
 [ -z "$bad" ] || printf "Headline too long:\n$bad\n"
 
 # check body lines length (75 max)
-bad=$(echo "$bodylines" | awk 'length>75 {print}' | sed 's,^,\t,')
+bad=$(echo "$bodylines" | grep -v '^Fixes:' | awk 'length>75 {print}' | sed 's,^,\t,')
 [ -z "$bad" ] || printf "Line too long:\n$bad\n"
 
+# check starting commit message with "It"
+bad=$(for commit in $commits ; do
+       firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
+       echo "$firstbodyline" | grep --color=always -ie '^It '
+done | sed 's,^,\t,')
+[ -z "$bad" ] || printf "Wrong beginning of commit message:\n$bad\n"
+
 # check tags spelling
 bad=$(echo "$tags" |
        grep -v '^\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by: [^,]* <.*@.*>$' |
@@ -134,7 +142,11 @@ IFS='
 fixtags=$(echo "$tags" | grep '^Fixes: ')
 bad=$(for fixtag in $fixtags ; do
        hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
-       good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
+       if git branch --contains $hash | grep -q '^\*' ; then
+               good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
+       else
+               good="reference not in current branch"
+       fi
        printf "$fixtag" | grep -v "^$good$"
 done | sed 's,^,\t,')
 [ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"