Skip to content

Commit 8dd7c47

Browse files
newrengitster
authored andcommitted
sparse-checkout: reject arguments in cone-mode that look like patterns
In sparse-checkout add/set under cone mode, the arguments passed are supposed to be directories rather than gitignore-style patterns. However, given the amount of effort spent in the manual discussing patterns, it is easy for users to assume they need to pass patterns such as /foo/* or !/bar/*/ or perhaps they really do ignore the directory rule and specify a random gitignore-style pattern like *.c To help catch such mistakes, throw an error if any of the positional arguments: * starts with any of '/!' * contains any of '*?[]' Inform users they can pass --skip-checks if they have a directory that really does have such special characters in its name. (We exclude '\' because of sparse-checkout's special handling of backslashes; see the MINGW test in t1091.46.) Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ce5043 commit 8dd7c47

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin/sparse-checkout.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,17 @@ static void sanitize_paths(int argc, const char **argv,
710710
if (prefix && *prefix && !core_sparse_checkout_cone)
711711
die(_("please run from the toplevel directory in non-cone mode"));
712712

713+
if (core_sparse_checkout_cone) {
714+
for (i = 0; i < argc; i++) {
715+
if (argv[i][0] == '/')
716+
die(_("specify directories rather than patterns (no leading slash)"));
717+
if (argv[i][0] == '!')
718+
die(_("specify directories rather than patterns. If your directory starts with a '!', pass --skip-checks"));
719+
if (strpbrk(argv[i], "*?[]"))
720+
die(_("specify directories rather than patterns. If your directory really has any of '*?[]\\' in it, pass --skip-checks"));
721+
}
722+
}
723+
713724
for (i = 0; i < argc; i++) {
714725
struct cache_entry *ce;
715726
struct index_state *index = the_repository->index;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
673673
git -C escaped reset --hard $COMMIT &&
674674
check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
675675
git -C escaped sparse-checkout init --cone &&
676-
git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
676+
git -C escaped sparse-checkout set --skip-checks zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
677677
cat >expect <<-\EOF &&
678678
/*
679679
!/*/

0 commit comments

Comments
 (0)