From: Elijah Newren <newren@xxxxxxxxx> In sparse-checkout add/set, in cone mode any specified directories will be transformed into appropriate patterns. In non-cone mode, the non-option arguments are treated as patterns. Since .git/info/sparse-checkout will ignore any patterns starting with a '#' (they are just gitignore patterns), if the user passes an argument starting with a '#' to sparse-checkout add/set in non-cone mode, it would just be treated as a comment and ignored. Error out in such cases, informing the user that they need to backslash escape it. Signed-off-by: Elijah Newren <newren@xxxxxxxxx> --- builtin/sparse-checkout.c | 5 +++++ t/t1091-sparse-checkout-builtin.sh | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 64583fa704f..74d64ada9f9 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -710,6 +710,11 @@ static void sanitize_paths(int argc, const char **argv, if (skip_checks) return; + if (!core_sparse_checkout_cone) + for (i = 0; i < argc; i++) + if (argv[i][0] == '#') + die(_("paths beginning with a '#' must be preceeded by a backslash")); + for (i = 0; i < argc; i++) { struct cache_entry *ce; struct index_state *index = the_repository->index; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 3b39329266b..3c811724d5d 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -853,4 +853,10 @@ test_expect_success 'by default, non-cone mode will warn on individual files' ' grep "pass a leading slash before paths.*if you want a single file" warning ' +test_expect_success 'paths starting with hash must be escaped in non-cone mode' ' + test_must_fail git -C repo sparse-checkout set --no-cone "#funny-path" 2>error && + + grep "paths beginning.*#.*must be preceeded by a backslash" error +' + test_done -- gitgitgadget