summaryrefslogtreecommitdiff
path: root/t/t1091-sparse-checkout-builtin.sh
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-01-31 20:16:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-31 21:05:29 (GMT)
commitbd64de42de28e5cdda7765d5de1c3ed34d4898cb (patch)
tree81300b9f2436a4a1f2a9bd621df7e9d6b98206c8 /t/t1091-sparse-checkout-builtin.sh
parentd585f0e7992ea7f025a5a91f46f2baa9e88f19f6 (diff)
downloadgit-bd64de42de28e5cdda7765d5de1c3ed34d4898cb.zip
git-bd64de42de28e5cdda7765d5de1c3ed34d4898cb.tar.gz
git-bd64de42de28e5cdda7765d5de1c3ed34d4898cb.tar.bz2
sparse-checkout: unquote C-style strings over --stdin
If a user somehow creates a directory with an asterisk (*) or backslash (\), then the "git sparse-checkout set" command will struggle to provide the correct pattern in the sparse-checkout file. When not in cone mode, the provided pattern is written directly into the sparse-checkout file. However, in cone mode we expect a list of paths to directories and then we convert those into patterns. Even more specifically, the goal is to always allow the following from the root of a repo: git ls-tree --name-only -d HEAD | git sparse-checkout set --stdin The ls-tree command provides directory names with an unescaped asterisk. It also quotes the directories that contain an escaped backslash. We must remove these quotes, then keep the escaped backslashes. Use unquote_c_style() when parsing lines from stdin. Command-line arguments will be parsed as-is, assuming the user can do the correct level of escaping from their environment to match the exact directory names. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1091-sparse-checkout-builtin.sh')
-rwxr-xr-xt/t1091-sparse-checkout-builtin.sh14
1 files changed, 13 insertions, 1 deletions
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index fb8718e..a46a310 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -405,7 +405,19 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
/zdoes\*not\*exist/
EOF
test_cmp expect escaped/.git/info/sparse-checkout &&
- check_read_tree_errors escaped "a zbad\\dir zdoes*exist"
+ check_read_tree_errors escaped "a zbad\\dir zdoes*exist" &&
+ git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin &&
+ cat >expect <<-\EOF &&
+ /*
+ !/*/
+ /deep/
+ /folder1/
+ /folder2/
+ /zbad\\dir/
+ /zdoes\*exist/
+ EOF
+ test_cmp expect escaped/.git/info/sparse-checkout &&
+ check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist"
'
test_done