scripts/checkpatch.pl | 4 ++-- scripts/get_maintainer.pl | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-)
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@163.com>
---
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)
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because their top_of_kernel_tree() checks require top-level directories that may not be present in a sparse working tree.
This series relaxes that check to match the files the scripts actually need and adds a regression test to keep that behavior from regressing.
Changes in v2:
- add a regression test for sparse checkout handling in checkpatch.pl and
get_maintainer.pl
CaoRuichuang (2):
scripts: allow checkpatch and get_maintainer in sparse checkouts
scripts: add sparse checkout regression test for checkpatch tools
scripts/checkpatch-sparse-checkout-test.sh | 48 ++++++++++++++++++++++
scripts/checkpatch.pl | 4 +-
scripts/get_maintainer.pl | 9 +---
3 files changed, 51 insertions(+), 10 deletions(-)
create mode 100755 scripts/checkpatch-sparse-checkout-test.sh
--
2.39.5 (Apple Git-154)
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@163.com>
---
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 e56374662..259abff97 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 4414194be..1d032f0e4 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)
On Mon, 2026-04-06 at 03:15 +0800, CaoRuichuang wrote: > 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. I still think this is unnecessary and you should just add --no-tree to the command line / script invocations of these tools.
Hi Joe, I re-tested this on a clean sparse checkout of the upstream tree. Both tools work fine with --no-tree: - scripts/checkpatch.pl --no-tree ... - scripts/get_maintainer.pl --no-tree ... So you are right that changing top_of_kernel_tree() is unnecessary for this workflow. I'll drop this series. Thanks, CaoRuichuang
Add a shell-based regression test that exercises checkpatch.pl and get_maintainer.pl from a minimal sparse checkout style tree.
This locks in the sparse checkout behavior added by the preceding patch and catches future regressions in top_of_kernel_tree() handling for these scripts.
Signed-off-by: CaoRuichuang <create0818@163.com>
---
scripts/checkpatch-sparse-checkout-test.sh | 48 ++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100755 scripts/checkpatch-sparse-checkout-test.sh
diff --git a/scripts/checkpatch-sparse-checkout-test.sh b/scripts/checkpatch-sparse-checkout-test.sh
new file mode 100755
index 000000000..02e2774a8
--- /dev/null
+++ b/scripts/checkpatch-sparse-checkout-test.sh
@@ -0,0 +1,48 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0
+
+srctree=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+tmpdir=$(mktemp -d)
+trap 'rm -rf "$tmpdir"' EXIT
+
+mkdir -p "$tmpdir/Documentation/process" "$tmpdir/scripts"
+
+for file in COPYING CREDITS Kbuild MAINTAINERS Makefile README; do
+ cp "$srctree/$file" "$tmpdir/$file"
+done
+
+cp "$srctree/Documentation/process/submitting-patches.rst" \
+ "$tmpdir/Documentation/process/"
+cp "$srctree/scripts/checkpatch.pl" "$tmpdir/scripts/"
+cp "$srctree/scripts/get_maintainer.pl" "$tmpdir/scripts/"
+cp "$srctree/scripts/spdxcheck.py" "$tmpdir/scripts/"
+cp "$srctree/scripts/spelling.txt" "$tmpdir/scripts/"
+
+git -C "$tmpdir" init -q
+git -C "$tmpdir" add \
+ COPYING CREDITS Kbuild MAINTAINERS Makefile README \
+ Documentation/process/submitting-patches.rst \
+ scripts/checkpatch.pl scripts/get_maintainer.pl \
+ scripts/spdxcheck.py scripts/spelling.txt
+
+checkpatch_out=$(
+ cd "$tmpdir" &&
+ perl scripts/checkpatch.pl --file Documentation/process/submitting-patches.rst \
+ 2>&1 || true
+)
+
+echo "$checkpatch_out" |
+ grep -q "Must be run from the top-level dir. of a kernel tree" &&
+ exit 1
+
+get_maintainer_out=$(
+ cd "$tmpdir" &&
+ perl scripts/get_maintainer.pl -f Documentation/process/submitting-patches.rst \
+ 2>&1
+)
+
+echo "$get_maintainer_out" |
+ grep -q "The current directory does not appear to be a linux kernel source tree" &&
+ exit 1
+
+echo "$get_maintainer_out" | grep -q "Jonathan Corbet" || exit 1
--
2.39.5 (Apple Git-154)
On Mon, 2026-04-06 at 02:55 +0800, CaoRuichuang wrote: > 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. So add / use the command-line --notree option instead ?
© 2016 - 2026 Red Hat, Inc.