[PATCH] scripts: allow checkpatch and get_maintainer in sparse checkouts
From: CaoRuichuang
Date: Sun Apr 05 2026 - 14:55:41 EST
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because top_of_kernel_tree() insists on top-level directories such as arch/, drivers/ and fs/ being present in the working tree.
That unnecessarily blocks common patch preparation workflows using partial clones or sparse checkouts, even when the files needed by these tools are present.
Relax the tree check to require only the top-level files and directories these scripts actually need so they continue to recognize full trees while also working from sparse checkouts.
Signed-off-by: CaoRuichuang <create0818@xxxxxxx>
---
scripts/checkpatch.pl | 4 ++--
scripts/get_maintainer.pl | 9 +--------
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e563746..259abff 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1397,10 +1397,10 @@ exit($exit);
sub top_of_kernel_tree {
my ($root) = @_;
+ # Allow sparse checkouts that still contain the files these scripts need.
my @tree_check = (
"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
- "README", "Documentation", "arch", "include", "drivers",
- "fs", "init", "ipc", "kernel", "lib", "scripts",
+ "README", "Documentation", "scripts",
);
foreach my $check (@tree_check) {
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 4414194..1d032f0 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -1157,6 +1157,7 @@ sub top_of_kernel_tree {
if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
$lk_path .= "/";
}
+ # Allow sparse checkouts that still contain the files these scripts need.
if ( (-f "${lk_path}COPYING")
&& (-f "${lk_path}CREDITS")
&& (-f "${lk_path}Kbuild")
@@ -1164,14 +1165,6 @@ sub top_of_kernel_tree {
&& (-f "${lk_path}Makefile")
&& (-f "${lk_path}README")
&& (-d "${lk_path}Documentation")
- && (-d "${lk_path}arch")
- && (-d "${lk_path}include")
- && (-d "${lk_path}drivers")
- && (-d "${lk_path}fs")
- && (-d "${lk_path}init")
- && (-d "${lk_path}ipc")
- && (-d "${lk_path}kernel")
- && (-d "${lk_path}lib")
&& (-d "${lk_path}scripts")) {
return 1;
}
--
2.39.5 (Apple Git-154)