Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b49ecfe

Browse files
ethomsonpks-t
authored andcommitted
refs:iterator: add tests to recurse symlinks
Ensure that we can recurse into directories via symbolic links.
1 parent 57c1745 commit b49ecfe

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

tests/refs/iterator.c

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ static git_repository *repo;
66

77
void test_refs_iterator__initialize(void)
88
{
9-
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
9+
repo = cl_git_sandbox_init("testrepo.git");
1010
}
1111

1212
void test_refs_iterator__cleanup(void)
1313
{
14-
git_repository_free(repo);
14+
cl_git_sandbox_cleanup();
1515
}
1616

1717
static const char *refnames[] = {
@@ -36,6 +36,36 @@ static const char *refnames[] = {
3636
"refs/tags/taggerless",
3737
"refs/tags/test",
3838
"refs/tags/wrapped_tag",
39+
NULL
40+
};
41+
42+
static const char *refnames_with_symlink[] = {
43+
"refs/heads/br2",
44+
"refs/heads/cannot-fetch",
45+
"refs/heads/chomped",
46+
"refs/heads/haacked",
47+
"refs/heads/link/a",
48+
"refs/heads/link/b",
49+
"refs/heads/link/c",
50+
"refs/heads/link/d",
51+
"refs/heads/master",
52+
"refs/heads/not-good",
53+
"refs/heads/packed",
54+
"refs/heads/packed-test",
55+
"refs/heads/subtrees",
56+
"refs/heads/test",
57+
"refs/heads/track-local",
58+
"refs/heads/trailing",
59+
"refs/notes/fanout",
60+
"refs/remotes/test/master",
61+
"refs/tags/annotated_tag_to_blob",
62+
"refs/tags/e90810b",
63+
"refs/tags/hard_tag",
64+
"refs/tags/point_to_blob",
65+
"refs/tags/taggerless",
66+
"refs/tags/test",
67+
"refs/tags/wrapped_tag",
68+
NULL
3969
};
4070

4171
static int refcmp_cb(const void *a, const void *b)
@@ -46,21 +76,21 @@ static int refcmp_cb(const void *a, const void *b)
4676
return strcmp(refa->name, refb->name);
4777
}
4878

49-
static void assert_all_refnames_match(git_vector *output)
79+
static void assert_all_refnames_match(const char **expected, git_vector *names)
5080
{
5181
size_t i;
5282
git_reference *ref;
5383

54-
cl_assert_equal_sz(output->length, ARRAY_SIZE(refnames));
55-
56-
git_vector_sort(output);
84+
git_vector_sort(names);
5785

58-
git_vector_foreach(output, i, ref) {
59-
cl_assert_equal_s(ref->name, refnames[i]);
86+
git_vector_foreach(names, i, ref) {
87+
cl_assert(expected[i] != NULL);
88+
cl_assert_equal_s(expected[i], ref->name);
6089
git_reference_free(ref);
6190
}
91+
cl_assert(expected[i] == NULL);
6292

63-
git_vector_free(output);
93+
git_vector_free(names);
6494
}
6595

6696
void test_refs_iterator__list(void)
@@ -82,7 +112,7 @@ void test_refs_iterator__list(void)
82112

83113
git_reference_iterator_free(iter);
84114

85-
assert_all_refnames_match(&output);
115+
assert_all_refnames_match(refnames, &output);
86116
}
87117

88118
void test_refs_iterator__empty(void)
@@ -115,7 +145,29 @@ void test_refs_iterator__foreach(void)
115145
git_vector output;
116146
cl_git_pass(git_vector_init(&output, 32, &refcmp_cb));
117147
cl_git_pass(git_reference_foreach(repo, refs_foreach_cb, &output));
118-
assert_all_refnames_match(&output);
148+
assert_all_refnames_match(refnames, &output);
149+
}
150+
151+
void test_refs_iterator__foreach_through_symlink(void)
152+
{
153+
git_vector output;
154+
155+
#ifdef GIT_WIN32
156+
cl_skip();
157+
#endif
158+
159+
cl_git_pass(git_vector_init(&output, 32, &refcmp_cb));
160+
161+
cl_git_pass(p_mkdir("refs", 0777));
162+
cl_git_mkfile("refs/a", "1234567890123456789012345678901234567890");
163+
cl_git_mkfile("refs/b", "1234567890123456789012345678901234567890");
164+
cl_git_mkfile("refs/c", "1234567890123456789012345678901234567890");
165+
cl_git_mkfile("refs/d", "1234567890123456789012345678901234567890");
166+
167+
cl_git_pass(p_symlink("../../../refs", "testrepo.git/refs/heads/link"));
168+
169+
cl_git_pass(git_reference_foreach(repo, refs_foreach_cb, &output));
170+
assert_all_refnames_match(refnames_with_symlink, &output);
119171
}
120172

121173
static int refs_foreach_cancel_cb(git_reference *reference, void *payload)
@@ -156,12 +208,11 @@ void test_refs_iterator__foreach_name(void)
156208
cl_git_pass(
157209
git_reference_foreach_name(repo, refs_foreach_name_cb, &output));
158210

159-
cl_assert_equal_sz(output.length, ARRAY_SIZE(refnames));
160211
git_vector_sort(&output);
161212

162213
git_vector_foreach(&output, i, name) {
163-
cl_assert_equal_s(name, refnames[i]);
164-
git__free(name);
214+
cl_assert(refnames[i] != NULL);
215+
cl_assert_equal_s(refnames[i], name);
165216
}
166217

167218
git_vector_free(&output);
@@ -194,7 +245,7 @@ void test_refs_iterator__concurrent_delete(void)
194245
const char *name;
195246
int error;
196247

197-
git_repository_free(repo);
248+
cl_git_sandbox_cleanup();
198249
repo = cl_git_sandbox_init("testrepo");
199250

200251
cl_git_pass(git_reference_iterator_new(&iter, repo));
@@ -215,7 +266,4 @@ void test_refs_iterator__concurrent_delete(void)
215266
cl_assert_equal_i(GIT_ITEROVER, error);
216267

217268
cl_assert_equal_i(full_count, concurrent_count);
218-
219-
cl_git_sandbox_cleanup();
220-
repo = NULL;
221269
}

0 commit comments

Comments
 (0)