зеркало из https://github.com/microsoft/git.git
sparse-checkout: escape all glob characters on write
The sparse-checkout patterns allow special globs according to fnmatch(3). When writing cone-mode patterns for paths containing these characters, they must be escaped. Use is_glob_special() to check which characters must be escaped this way, and add a path to the tests that contains all glob characters at once. Note that ']' is not special, since the initial bracket '[' is escaped. Reported-by: Jeff King <peff@peff.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
e55682ea26
Коммит
e53ffe2704
|
@ -149,7 +149,7 @@ static char *escaped_pattern(char *pattern)
|
||||||
struct strbuf final = STRBUF_INIT;
|
struct strbuf final = STRBUF_INIT;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '*' || *p == '\\')
|
if (is_glob_special(*p))
|
||||||
strbuf_addch(&final, '\\');
|
strbuf_addch(&final, '\\');
|
||||||
|
|
||||||
strbuf_addch(&final, *p);
|
strbuf_addch(&final, *p);
|
||||||
|
|
|
@ -381,20 +381,21 @@ test_expect_success 'pattern-checks: contained glob characters' '
|
||||||
done
|
done
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
|
test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
|
||||||
git clone repo escaped &&
|
git clone repo escaped &&
|
||||||
TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
|
TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
|
||||||
NEWTREE=$(git -C escaped mktree <<-EOF
|
NEWTREE=$(git -C escaped mktree <<-EOF
|
||||||
$(git -C escaped ls-tree HEAD)
|
$(git -C escaped ls-tree HEAD)
|
||||||
040000 tree $TREEOID zbad\\dir
|
040000 tree $TREEOID zbad\\dir
|
||||||
040000 tree $TREEOID zdoes*exist
|
040000 tree $TREEOID zdoes*exist
|
||||||
|
040000 tree $TREEOID zglob[!a]?
|
||||||
EOF
|
EOF
|
||||||
) &&
|
) &&
|
||||||
COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) &&
|
COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) &&
|
||||||
git -C escaped reset --hard $COMMIT &&
|
git -C escaped reset --hard $COMMIT &&
|
||||||
check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" &&
|
check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
|
||||||
git -C escaped sparse-checkout init --cone &&
|
git -C escaped sparse-checkout init --cone &&
|
||||||
git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" &&
|
git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
|
||||||
cat >expect <<-\EOF &&
|
cat >expect <<-\EOF &&
|
||||||
/*
|
/*
|
||||||
!/*/
|
!/*/
|
||||||
|
@ -403,9 +404,10 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
|
||||||
/zbad\\dir/bogus/
|
/zbad\\dir/bogus/
|
||||||
/zdoes\*exist/
|
/zdoes\*exist/
|
||||||
/zdoes\*not\*exist/
|
/zdoes\*not\*exist/
|
||||||
|
/zglob\[!a]\?/
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect escaped/.git/info/sparse-checkout &&
|
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 zglob[!a]?" &&
|
||||||
git -C escaped ls-tree -d --name-only HEAD >list-expect &&
|
git -C escaped ls-tree -d --name-only HEAD >list-expect &&
|
||||||
git -C escaped sparse-checkout set --stdin <list-expect &&
|
git -C escaped sparse-checkout set --stdin <list-expect &&
|
||||||
cat >expect <<-\EOF &&
|
cat >expect <<-\EOF &&
|
||||||
|
@ -416,9 +418,10 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' '
|
||||||
/folder2/
|
/folder2/
|
||||||
/zbad\\dir/
|
/zbad\\dir/
|
||||||
/zdoes\*exist/
|
/zdoes\*exist/
|
||||||
|
/zglob\[!a]\?/
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect escaped/.git/info/sparse-checkout &&
|
test_cmp expect escaped/.git/info/sparse-checkout &&
|
||||||
check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" &&
|
check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
|
||||||
git -C escaped sparse-checkout list >list-actual &&
|
git -C escaped sparse-checkout list >list-actual &&
|
||||||
test_cmp list-expect list-actual
|
test_cmp list-expect list-actual
|
||||||
'
|
'
|
||||||
|
|
Загрузка…
Ссылка в новой задаче