The git commit message can be confusing, Try to clarify the message a bit to reduce the confusion when emitted. Show the correct form using Please use git commit description style 'commit <12+ chars of sha1> ("<title line>")' and if the git commit sha1 is unique, show the right sha1 to use with the actual title
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -634,6 +634,8 @@ sub git_commit_info { · 633 unmodified lines | ||
| 634 | 634 | $output =~ s/^\s*//gm; |
| 635 | 635 | my @lines = split("\n", $output); |
| 636 | 636 | |
| 637 | + return ($id, $desc) if ($#lines < 0); | |
| 638 | + | |
| 637 | 639 | if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { |
| 638 | 640 | # Maybe one day convert this block of bash into something that returns |
| 639 | 641 | # all matching commit ids, but it's very slow... |
| @@ -2173,21 +2175,38 @@ sub process { · 1533 unmodified lines | ||
| 2173 | 2175 | "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); |
| 2174 | 2176 | } |
| 2175 | 2177 | |
| 2176 | −# Check for improperly formed commit descriptions | |
| 2177 | − if ($in_commit_log && | |
| 2178 | − $line =~ /\bcommit\s+[0-9a-f]{5,}/i && | |
| 2179 | − !($line =~ /\b[Cc]ommit [0-9a-f]{12,40} \("/ || | |
| 2180 | − ($line =~ /\b[Cc]ommit [0-9a-f]{12,40}\s*$/ && | |
| 2181 | − defined $rawlines[$linenr] && | |
| 2182 | − $rawlines[$linenr] =~ /^\s*\("/))) { | |
| 2183 | − $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i; | |
| 2178 | +# Check for git id commit length and improperly formed commit descriptions | |
| 2179 | + if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { | |
| 2184 | 2180 | my $init_char = $1; |
| 2185 | 2181 | my $orig_commit = lc($2); |
| 2186 | − my $id = '01234567890ab'; | |
| 2187 | − my $desc = 'commit description'; | |
| 2188 | − ($id, $desc) = git_commit_info($orig_commit, $id, $desc); | |
| 2189 | − ERROR("GIT_COMMIT_ID", | |
| 2190 | − "Please use 12 or more chars for the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr); | |
| 2182 | + my $short = 1; | |
| 2183 | + my $long = 0; | |
| 2184 | + my $case = 1; | |
| 2185 | + my $space = 1; | |
| 2186 | + my $hasdesc = 0; | |
| 2187 | + my $id = '0123456789ab'; | |
| 2188 | + my $orig_desc = "commit description"; | |
| 2189 | + my $description = ""; | |
| 2190 | + | |
| 2191 | + $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i); | |
| 2192 | + $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); | |
| 2193 | + $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); | |
| 2194 | + $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); | |
| 2195 | + if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { | |
| 2196 | + $orig_desc = $1; | |
| 2197 | + } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && | |
| 2198 | + defined $rawlines[$linenr] && | |
| 2199 | + $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { | |
| 2200 | + $orig_desc = $1; | |
| 2201 | + } | |
| 2202 | + | |
| 2203 | + ($id, $description) = git_commit_info($orig_commit, | |
| 2204 | + $id, $orig_desc); | |
| 2205 | + | |
| 2206 | + if ($short || $long || $space || $case || ($orig_desc ne $description)) { | |
| 2207 | + ERROR("GIT_COMMIT_ID", | |
| 2208 | + "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr); | |
| 2209 | + } | |
| 2191 | 2210 | } |
| 2192 | 2211 | |
| 2193 | 2212 | # Check for added, moved or deleted files |