hashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {
/* pe->pattern starts with "/", skip it */
- string_list_insert(&sl, pe->pattern + 1);
+ string_list_append(&sl, pe->pattern + 1);
}
string_list_sort(&sl);
+ string_list_remove_duplicates(&sl, 0);
for (i = 0; i < sl.nr; i++) {
quote_c_style(sl.items[i].string, NULL, stdout, 0);
if (!hashmap_contains_parent(&pl->recursive_hashmap,
pe->pattern,
&parent_pattern))
- string_list_insert(&sl, pe->pattern);
+ string_list_append(&sl, pe->pattern);
}
string_list_sort(&sl);
if (!hashmap_contains_parent(&pl->recursive_hashmap,
pe->pattern,
&parent_pattern))
- string_list_insert(&sl, pe->pattern);
+ string_list_append(&sl, pe->pattern);
}
strbuf_release(&parent_pattern);
test_cmp expect out
'
+test_expect_success 'sparse-checkout deduplicates repeated cone patterns' '
+ rm -f repo/.git/info/sparse-checkout &&
+ git -C repo sparse-checkout init --cone &&
+ git -C repo sparse-checkout add --stdin <<-\EOF &&
+ foo/bar/baz
+ a/b/c
+ foo/bar/baz
+ a/b
+ EOF
+ cat >expect <<-\EOF &&
+ /*
+ !/*/
+ /a/
+ !/a/*/
+ /foo/
+ !/foo/*/
+ /foo/bar/
+ !/foo/bar/*/
+ /a/b/
+ /foo/bar/baz/
+ EOF
+ test_cmp expect repo/.git/info/sparse-checkout
+'
+
+test_expect_success 'sparse-checkout list deduplicates repeated cone patterns' '
+ rm -f repo/.git/info/sparse-checkout &&
+ git -C repo sparse-checkout init --cone &&
+ cat <<-\EOF >repo/.git/info/sparse-checkout &&
+ /*
+ !/*/
+ /a/
+ !/a/*/
+ /foo/
+ !/foo/*/
+ /foo/bar/
+ !/foo/bar/*/
+ /a/b/
+ /foo/bar/baz/
+ /foo/bar/baz/
+ EOF
+ git -C repo sparse-checkout list >actual &&
+ cat <<-\EOF >expect &&
+ a/b
+ foo/bar/baz
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'malformed cone-mode patterns' '
git -C repo sparse-checkout init --cone &&
mkdir -p repo/foo/bar &&