Skip to content

Commit 9e6d3e6

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41de0c6 commit 9e6d3e6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

dir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
651651
return;
652652
}
653653

654-
if (strstr(given->pattern, "**")) {
654+
if (given->patternlen <= 2 ||
655+
strstr(given->pattern, "**")) {
655656
/* Not a cone pattern. */
656657
warning(_("unrecognized pattern: '%s'"), given->pattern);
657658
goto clear_hashmaps;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,13 @@ test_expect_success 'pattern-checks: /A/**/B/' '
339339
check_files repo/deep/deeper1 "deepest"
340340
'
341341

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+
342351
test_done

0 commit comments

Comments
 (0)