sparse-checkout: detect short patterns
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>
Derrick Stolee committed
Jan 24, 2020 at 21:19 UTC
9e6d3e64175713bc0007f3012ea288f4dfc0a399
2 files changed
+11
-1
dir.c
+2
-1
@@ -651,7 +651,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
651
return;
652
}
653
654
- if (strstr(given->pattern, "**")) {
654
+ if (given->patternlen <= 2 ||
655
+ strstr(given->pattern, "**")) {
656
/* Not a cone pattern. */
657
warning(_("unrecognized pattern: '%s'"), given->pattern);
658
goto clear_hashmaps;
t/t1091-sparse-checkout-builtin.sh
+9
@@ -339,4 +339,13 @@ test_expect_success 'pattern-checks: /A/**/B/' '
339
check_files repo/deep/deeper1 "deepest"
340
'
341
342
+test_expect_success 'pattern-checks: too short' '
343
+ cat >repo/.git/info/sparse-checkout <<-\EOF &&
344
+ /*
345
+ !/*/
346
+ /a
347
+ EOF
348
+ check_read_tree_errors repo "a" "disabling cone pattern matching"
349
+'
350
+
351
test_done