@@ -6,12 +6,12 @@ static git_repository *repo;
6
6
7
7
void test_refs_iterator__initialize (void )
8
8
{
9
- cl_git_pass ( git_repository_open ( & repo , cl_fixture ("testrepo.git" )) );
9
+ repo = cl_git_sandbox_init ("testrepo.git" );
10
10
}
11
11
12
12
void test_refs_iterator__cleanup (void )
13
13
{
14
- git_repository_free ( repo );
14
+ cl_git_sandbox_cleanup ( );
15
15
}
16
16
17
17
static const char * refnames [] = {
@@ -36,6 +36,36 @@ static const char *refnames[] = {
36
36
"refs/tags/taggerless" ,
37
37
"refs/tags/test" ,
38
38
"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
39
69
};
40
70
41
71
static int refcmp_cb (const void * a , const void * b )
@@ -46,21 +76,21 @@ static int refcmp_cb(const void *a, const void *b)
46
76
return strcmp (refa -> name , refb -> name );
47
77
}
48
78
49
- static void assert_all_refnames_match (git_vector * output )
79
+ static void assert_all_refnames_match (const char * * expected , git_vector * names )
50
80
{
51
81
size_t i ;
52
82
git_reference * ref ;
53
83
54
- cl_assert_equal_sz (output -> length , ARRAY_SIZE (refnames ));
55
-
56
- git_vector_sort (output );
84
+ git_vector_sort (names );
57
85
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 );
60
89
git_reference_free (ref );
61
90
}
91
+ cl_assert (expected [i ] == NULL );
62
92
63
- git_vector_free (output );
93
+ git_vector_free (names );
64
94
}
65
95
66
96
void test_refs_iterator__list (void )
@@ -82,7 +112,7 @@ void test_refs_iterator__list(void)
82
112
83
113
git_reference_iterator_free (iter );
84
114
85
- assert_all_refnames_match (& output );
115
+ assert_all_refnames_match (refnames , & output );
86
116
}
87
117
88
118
void test_refs_iterator__empty (void )
@@ -115,7 +145,29 @@ void test_refs_iterator__foreach(void)
115
145
git_vector output ;
116
146
cl_git_pass (git_vector_init (& output , 32 , & refcmp_cb ));
117
147
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 );
119
171
}
120
172
121
173
static int refs_foreach_cancel_cb (git_reference * reference , void * payload )
@@ -156,12 +208,11 @@ void test_refs_iterator__foreach_name(void)
156
208
cl_git_pass (
157
209
git_reference_foreach_name (repo , refs_foreach_name_cb , & output ));
158
210
159
- cl_assert_equal_sz (output .length , ARRAY_SIZE (refnames ));
160
211
git_vector_sort (& output );
161
212
162
213
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 );
165
216
}
166
217
167
218
git_vector_free (& output );
@@ -194,7 +245,7 @@ void test_refs_iterator__concurrent_delete(void)
194
245
const char * name ;
195
246
int error ;
196
247
197
- git_repository_free ( repo );
248
+ cl_git_sandbox_cleanup ( );
198
249
repo = cl_git_sandbox_init ("testrepo" );
199
250
200
251
cl_git_pass (git_reference_iterator_new (& iter , repo ));
@@ -215,7 +266,4 @@ void test_refs_iterator__concurrent_delete(void)
215
266
cl_assert_equal_i (GIT_ITEROVER , error );
216
267
217
268
cl_assert_equal_i (full_count , concurrent_count );
218
-
219
- cl_git_sandbox_cleanup ();
220
- repo = NULL ;
221
269
}
0 commit comments