@matheusbsbs / matheus-bagliano / commits / e55682ea26
Fork 0

sparse-checkout: use C-style quotes in 'list' subcommand

When in cone mode, the 'git sparse-checkout list' subcommand lists the directories included in the sparse cone. When these directories contain odd characters, such as a backslash, then we need to use C-style quotes similar to 'git ls-tree'. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 31, 2020 at 20:16 UTC e55682ea2640dd3aa002a2657c32bdd1d85b44e9
2 files changed +9 -4
builtin/sparse-checkout.c
+4 -2
@@ -78,8 +78,10 @@ static int sparse_checkout_list(int argc, const char **argv)
78
79 string_list_sort(&sl);
80
81 - for (i = 0; i < sl.nr; i++)
82 - printf("%s\n", sl.items[i].string);
81 + for (i = 0; i < sl.nr; i++) {
82 + quote_c_style(sl.items[i].string, NULL, stdout, 0);
83 + printf("\n");
84 + }
85
86 return 0;
87 }
t/t1091-sparse-checkout-builtin.sh
+5 -2
@@ -406,7 +406,8 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
406 EOF
407 test_cmp expect escaped/.git/info/sparse-checkout &&
408 check_read_tree_errors escaped "a zbad\\dir zdoes*exist" &&
409 - git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin &&
409 + git -C escaped ls-tree -d --name-only HEAD >list-expect &&
410 + git -C escaped sparse-checkout set --stdin <list-expect &&
411 cat >expect <<-\EOF &&
412 /*
413 !/*/
@@ -417,7 +418,9 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
418 /zdoes\*exist/
419 EOF
420 test_cmp expect escaped/.git/info/sparse-checkout &&
420 - check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist"
421 + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" &&
422 + git -C escaped sparse-checkout list >list-actual &&
423 + test_cmp list-expect list-actual
424 '
425
426 test_done