Skip to content

Commit a8dd86b

Browse files
teknoravertorvalds
authored andcommitted
checkpatch.pl: warn on invalid commit id
It can happen that a commit message refers to an invalid commit id, because the referenced hash changed following a rebase, or simply by mistake. Add a check in checkpatch.pl which checks that an hash referenced by a Fixes tag, or just cited in the commit message, is a valid commit id. $ scripts/checkpatch.pl <<'EOF' Subject: [PATCH] test commit Sample test commit to test checkpatch.pl Commit 1da177e ("Linux-2.6.12-rc2") really exists, commit 0bba044 ("tree") is valid but not a commit, while commit b4cc0b1c0cca ("unknown") is invalid. Fixes: f0cacc14cade ("unknown") Fixes: 1da177e ("Linux-2.6.12-rc2") EOF WARNING: Unknown commit id '0bba044c4ce7', maybe rebased or not pulled? #8: commit 0bba044 ("tree") is valid but not a commit, WARNING: Unknown commit id 'b4cc0b1c0cca', maybe rebased or not pulled? #9: while commit b4cc0b1c0cca ("unknown") is invalid. WARNING: Unknown commit id 'f0cacc14cade', maybe rebased or not pulled? #11: Fixes: f0cacc14cade ("unknown") total: 0 errors, 3 warnings, 4 lines checked Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Matteo Croce <[email protected]> Cc: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ffbce89 commit a8dd86b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scripts/checkpatch.pl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,17 @@ sub process {
29002900
}
29012901
}
29022902

2903+
# check for invalid commit id
2904+
if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
2905+
my $id;
2906+
my $description;
2907+
($id, $description) = git_commit_info($2, undef, undef);
2908+
if (!defined($id)) {
2909+
WARN("UNKNOWN_COMMIT_ID",
2910+
"Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);
2911+
}
2912+
}
2913+
29032914
# ignore non-hunk lines and lines being removed
29042915
next if (!$hunk_line || $line =~ /^-/);
29052916

0 commit comments

Comments
 (0)