]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: detect short patterns
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 24 Jan 2020 21:19:37 +0000 (21:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jan 2020 21:26:54 +0000 (13:26 -0800)
In cone mode, the shortest pattern the sparse-checkout command will
write into the sparse-checkout file is "/*". This is handled carefully
in add_pattern_to_hashsets(), so warn if any other pattern is this
short. This will assist future pattern checks by allowing us to assume
there are at least three characters in the pattern.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t1091-sparse-checkout-builtin.sh

diff --git a/dir.c b/dir.c
index 40fed73a947bad3837839af8195cfd06442b7324..c2e585607e1962d084271f608938efc8f4b7206b 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -651,7 +651,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
                return;
        }
 
-       if (strstr(given->pattern, "**")) {
+       if (given->patternlen <= 2 ||
+           strstr(given->pattern, "**")) {
                /* Not a cone pattern. */
                warning(_("unrecognized pattern: '%s'"), given->pattern);
                goto clear_hashmaps;
index e2e45dc7fd6351ef574ee6fb52027b726e50d6a6..2e575347995b1518f4ebfbc02be8c667d62d2d67 100755 (executable)
@@ -339,4 +339,13 @@ test_expect_success 'pattern-checks: /A/**/B/' '
        check_files repo/deep/deeper1 "deepest"
 '
 
+test_expect_success 'pattern-checks: too short' '
+       cat >repo/.git/info/sparse-checkout <<-\EOF &&
+       /*
+       !/*/
+       /a
+       EOF
+       check_read_tree_errors repo "a" "disabling cone pattern matching"
+'
+
 test_done