1 #include "clar_libgit2.h"
3 #include "repository.h"
5 #include "iterator_helpers.h"
6 #include "../submodule/submodule_helpers.h"
9 static git_repository
*g_repo
;
11 void test_iterator_index__initialize(void)
15 void test_iterator_index__cleanup(void)
17 cl_git_sandbox_cleanup();
21 static void index_iterator_test(
25 git_iterator_flag_t flags
,
27 const char **expected_names
,
28 const char **expected_oids
)
32 const git_index_entry
*entry
;
33 int error
, count
= 0, caps
;
34 git_iterator_options iter_opts
= GIT_ITERATOR_OPTIONS_INIT
;
36 g_repo
= cl_git_sandbox_init(sandbox
);
38 cl_git_pass(git_repository_index(&index
, g_repo
));
39 caps
= git_index_caps(index
);
41 iter_opts
.flags
= flags
;
42 iter_opts
.start
= start
;
45 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &iter_opts
));
47 while (!(error
= git_iterator_advance(&entry
, i
))) {
50 if (expected_names
!= NULL
)
51 cl_assert_equal_s(expected_names
[count
], entry
->path
);
53 if (expected_oids
!= NULL
) {
55 cl_git_pass(git_oid_fromstr(&oid
, expected_oids
[count
]));
56 cl_assert_equal_oid(&oid
, &entry
->id
);
62 cl_assert_equal_i(GIT_ITEROVER
, error
);
64 cl_assert_equal_i(expected_count
, count
);
68 cl_assert(caps
== git_index_caps(index
));
69 git_index_free(index
);
72 static const char *expected_index_0
[] = {
90 "sub/subdir_test2.txt",
91 "subdir/.gitattributes",
93 "subdir/subdir_test1",
94 "subdir/subdir_test2.txt",
95 "subdir2/subdir2_test1",
98 static const char *expected_index_oids_0
[] = {
99 "556f8c827b8e4a02ad5cab77dca2bcb3e226b0b3",
100 "3b74db7ab381105dc0d28f8295a77f6a82989292",
101 "2c66e14f77196ea763fb1e41612c1aa2bc2d8ed2",
102 "c485abe35abd4aa6fd83b076a78bbea9e2e7e06c",
103 "d800886d9c86731ae5c4a62b0b77c437015e00d2",
104 "2b40c5aca159b04ea8d20ffe36cdf8b09369b14a",
105 "5819a185d77b03325aaf87cafc771db36f6ddca7",
106 "ff69f8639ce2e6010b3f33a74160aad98b48da2b",
107 "45141a79a77842c59a63229403220a4e4be74e3d",
108 "4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
109 "108bb4e7fd7b16490dc33ff7d972151e73d7166e",
110 "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
111 "3e42ffc54a663f9401cc25843d6c0e71a33e4249",
112 "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
113 "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
114 "9e5bdc47d6a80f2be0ea3049ad74231b94609242",
115 "e563cf4758f0d646f1b14b76016aa17fa9e549a4",
116 "fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
117 "99eae476896f4907224978b88e5ecaa6c5bb67a9",
118 "3e42ffc54a663f9401cc25843d6c0e71a33e4249",
119 "e563cf4758f0d646f1b14b76016aa17fa9e549a4",
120 "fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
121 "dccada462d3df8ac6de596fb8c896aba9344f941"
124 void test_iterator_index__0(void)
127 "attr", NULL
, NULL
, 0, ARRAY_SIZE(expected_index_0
),
128 expected_index_0
, expected_index_oids_0
);
131 static const char *expected_index_1
[] = {
136 "staged_changes_file_deleted",
137 "staged_changes_modified_file",
139 "staged_new_file_deleted_file",
140 "staged_new_file_modified_file",
142 "subdir/current_file",
143 "subdir/deleted_file",
144 "subdir/modified_file",
147 static const char* expected_index_oids_1
[] = {
148 "a0de7e0ac200c489c41c59dfa910154a70264e6e",
149 "5452d32f1dd538eb0405e8a83cc185f79e25e80f",
150 "452e4244b5d083ddf0460acf1ecc74db9dcfa11a",
151 "55d316c9ba708999f1918e9677d01dfcae69c6b9",
152 "a6be623522ce87a1d862128ac42672604f7b468b",
153 "906ee7711f4f4928ddcb2a5f8fbc500deba0d2a8",
154 "529a16e8e762d4acb7b9636ff540a00831f9155a",
155 "90b8c29d8ba39434d1c63e1b093daaa26e5bd972",
156 "ed062903b8f6f3dccb2fa81117ba6590944ef9bd",
157 "e8ee89e15bbe9b20137715232387b3de5b28972e",
158 "53ace0d1cc1145a5f4fe4f78a186a60263190733",
159 "1888c805345ba265b0ee9449b8877b6064592058",
160 "a6191982709b746d5650e93c2acf34ef74e11504"
163 void test_iterator_index__1(void)
166 "status", NULL
, NULL
, 0, ARRAY_SIZE(expected_index_1
),
167 expected_index_1
, expected_index_oids_1
);
170 static const char *expected_index_range
[] = {
177 static const char *expected_index_oids_range
[] = {
178 "45141a79a77842c59a63229403220a4e4be74e3d",
179 "4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
180 "108bb4e7fd7b16490dc33ff7d972151e73d7166e",
181 "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
184 void test_iterator_index__range(void)
187 "attr", "root", "root", 0, ARRAY_SIZE(expected_index_range
),
188 expected_index_range
, expected_index_oids_range
);
191 void test_iterator_index__range_empty_0(void)
194 "attr", "empty", "empty", 0, 0, NULL
, NULL
);
197 void test_iterator_index__range_empty_1(void)
200 "attr", "z_empty_after", NULL
, 0, 0, NULL
, NULL
);
203 void test_iterator_index__range_empty_2(void)
206 "attr", NULL
, ".aaa_empty_before", 0, 0, NULL
, NULL
);
209 static void check_index_range(
210 git_repository
*repo
,
218 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
219 int error
, count
, caps
;
220 bool is_ignoring_case
;
222 cl_git_pass(git_repository_index(&index
, repo
));
224 caps
= git_index_caps(index
);
225 is_ignoring_case
= ((caps
& GIT_INDEX_CAPABILITY_IGNORE_CASE
) != 0);
227 if (ignore_case
!= is_ignoring_case
)
228 cl_git_pass(git_index_set_caps(index
, caps
^ GIT_INDEX_CAPABILITY_IGNORE_CASE
));
231 i_opts
.start
= start
;
234 cl_git_pass(git_iterator_for_index(&i
, repo
, index
, &i_opts
));
236 cl_assert(git_iterator_ignore_case(i
) == ignore_case
);
238 for (count
= 0; !(error
= git_iterator_advance(NULL
, i
)); ++count
)
241 cl_assert_equal_i(GIT_ITEROVER
, error
);
242 cl_assert_equal_i(expected_count
, count
);
244 git_iterator_free(i
);
245 git_index_free(index
);
248 void test_iterator_index__range_icase(void)
253 g_repo
= cl_git_sandbox_init("testrepo");
255 /* reset index to match HEAD */
256 cl_git_pass(git_repository_head_tree(&head
, g_repo
));
257 cl_git_pass(git_repository_index(&index
, g_repo
));
258 cl_git_pass(git_index_read_tree(index
, head
));
259 cl_git_pass(git_index_write(index
));
261 git_index_free(index
);
263 /* do some ranged iterator checks toggling case sensitivity */
264 check_index_range(g_repo
, "B", "C", false, 0);
265 check_index_range(g_repo
, "B", "C", true, 1);
266 check_index_range(g_repo
, "a", "z", false, 3);
267 check_index_range(g_repo
, "a", "z", true, 4);
270 static const char *expected_index_cs
[] = {
271 "B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
272 "a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
275 static const char *expected_index_ci
[] = {
276 "a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
277 "k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
280 void test_iterator_index__case_folding(void)
282 git_str path
= GIT_STR_INIT
;
285 cl_git_pass(git_str_joinpath(&path
, cl_fixture("icase"), ".gitted/CoNfIg"));
286 fs_is_ci
= git_fs_path_exists(path
.ptr
);
287 git_str_dispose(&path
);
290 "icase", NULL
, NULL
, 0, ARRAY_SIZE(expected_index_cs
),
291 fs_is_ci
? expected_index_ci
: expected_index_cs
, NULL
);
293 cl_git_sandbox_cleanup();
296 "icase", NULL
, NULL
, GIT_ITERATOR_IGNORE_CASE
,
297 ARRAY_SIZE(expected_index_ci
), expected_index_ci
, NULL
);
299 cl_git_sandbox_cleanup();
302 "icase", NULL
, NULL
, GIT_ITERATOR_DONT_IGNORE_CASE
,
303 ARRAY_SIZE(expected_index_cs
), expected_index_cs
, NULL
);
306 /* Index contents (including pseudotrees):
308 * 0: a 5: F 10: k/ 16: L/
309 * 1: B 6: g 11: k/1 17: L/1
310 * 2: c 7: H 12: k/a 18: L/a
311 * 3: D 8: i 13: k/B 19: L/B
312 * 4: e 9: J 14: k/c 20: L/c
315 * 0: B 5: L/ 11: a 16: k/
316 * 1: D 6: L/1 12: c 17: k/1
317 * 2: F 7: L/B 13: e 18: k/B
318 * 3: H 8: L/D 14: g 19: k/D
319 * 4: J 9: L/a 15: i 20: k/a
323 void test_iterator_index__icase_0(void)
326 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
329 g_repo
= cl_git_sandbox_init("icase");
331 cl_git_pass(git_repository_index(&index
, g_repo
));
333 /* autoexpand with no tree entries for index */
334 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, NULL
));
335 expect_iterator_items(i
, 20, NULL
, 20, NULL
);
336 git_iterator_free(i
);
338 /* auto expand with tree entries */
339 i_opts
.flags
= GIT_ITERATOR_INCLUDE_TREES
;
340 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
341 expect_iterator_items(i
, 22, NULL
, 22, NULL
);
342 git_iterator_free(i
);
344 /* no auto expand (implies trees included) */
345 i_opts
.flags
= GIT_ITERATOR_DONT_AUTOEXPAND
;
346 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
347 expect_iterator_items(i
, 12, NULL
, 22, NULL
);
348 git_iterator_free(i
);
350 git_index_free(index
);
353 void test_iterator_index__icase_1(void)
356 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
360 g_repo
= cl_git_sandbox_init("icase");
362 cl_git_pass(git_repository_index(&index
, g_repo
));
363 caps
= git_index_caps(index
);
365 /* force case sensitivity */
366 cl_git_pass(git_index_set_caps(index
, caps
& ~GIT_INDEX_CAPABILITY_IGNORE_CASE
));
368 /* autoexpand with no tree entries over range */
371 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
372 expect_iterator_items(i
, 7, NULL
, 7, NULL
);
373 git_iterator_free(i
);
377 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
378 expect_iterator_items(i
, 3, NULL
, 3, NULL
);
379 git_iterator_free(i
);
381 /* auto expand with tree entries */
382 i_opts
.flags
= GIT_ITERATOR_INCLUDE_TREES
;
386 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
387 expect_iterator_items(i
, 8, NULL
, 8, NULL
);
388 git_iterator_free(i
);
392 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
393 expect_iterator_items(i
, 4, NULL
, 4, NULL
);
394 git_iterator_free(i
);
396 /* no auto expand (implies trees included) */
397 i_opts
.flags
= GIT_ITERATOR_DONT_AUTOEXPAND
;
401 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
402 expect_iterator_items(i
, 5, NULL
, 8, NULL
);
403 git_iterator_free(i
);
407 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
408 expect_iterator_items(i
, 1, NULL
, 4, NULL
);
409 git_iterator_free(i
);
411 /* force case insensitivity */
412 cl_git_pass(git_index_set_caps(index
, caps
| GIT_INDEX_CAPABILITY_IGNORE_CASE
));
414 /* autoexpand with no tree entries over range */
419 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
420 expect_iterator_items(i
, 13, NULL
, 13, NULL
);
421 git_iterator_free(i
);
425 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
426 expect_iterator_items(i
, 5, NULL
, 5, NULL
);
427 git_iterator_free(i
);
429 /* auto expand with tree entries */
430 i_opts
.flags
= GIT_ITERATOR_INCLUDE_TREES
;
434 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
435 expect_iterator_items(i
, 14, NULL
, 14, NULL
);
436 git_iterator_free(i
);
440 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
441 expect_iterator_items(i
, 6, NULL
, 6, NULL
);
442 git_iterator_free(i
);
444 /* no auto expand (implies trees included) */
445 i_opts
.flags
= GIT_ITERATOR_DONT_AUTOEXPAND
;
449 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
450 expect_iterator_items(i
, 9, NULL
, 14, NULL
);
451 git_iterator_free(i
);
455 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
456 expect_iterator_items(i
, 1, NULL
, 6, NULL
);
457 git_iterator_free(i
);
459 cl_git_pass(git_index_set_caps(index
, caps
));
460 git_index_free(index
);
463 void test_iterator_index__pathlist(void)
466 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
470 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
471 cl_git_pass(git_vector_insert(&filelist
, "a"));
472 cl_git_pass(git_vector_insert(&filelist
, "B"));
473 cl_git_pass(git_vector_insert(&filelist
, "c"));
474 cl_git_pass(git_vector_insert(&filelist
, "D"));
475 cl_git_pass(git_vector_insert(&filelist
, "e"));
476 cl_git_pass(git_vector_insert(&filelist
, "k/1"));
477 cl_git_pass(git_vector_insert(&filelist
, "k/a"));
478 cl_git_pass(git_vector_insert(&filelist
, "L/1"));
480 g_repo
= cl_git_sandbox_init("icase");
482 cl_git_pass(git_repository_index(&index
, g_repo
));
484 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
485 i_opts
.pathlist
.count
= filelist
.length
;
489 const char *expected
[] = {
490 "B", "D", "L/1", "a", "c", "e", "k/1", "k/a" };
491 size_t expected_len
= 8;
495 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
497 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
498 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
499 git_iterator_free(i
);
502 /* Case INsensitive */
504 const char *expected
[] = {
505 "a", "B", "c", "D", "e", "k/1", "k/a", "L/1" };
506 size_t expected_len
= 8;
510 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
512 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
513 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
514 git_iterator_free(i
);
517 /* Set a start, but no end. Case sensitive. */
519 const char *expected
[] = { "c", "e", "k/1", "k/a" };
520 size_t expected_len
= 4;
524 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
526 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
527 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
528 git_iterator_free(i
);
531 /* Set a start, but no end. Case INsensitive. */
533 const char *expected
[] = { "c", "D", "e", "k/1", "k/a", "L/1" };
534 size_t expected_len
= 6;
538 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
540 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
541 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
542 git_iterator_free(i
);
545 /* Set no start, but an end. Case sensitive. */
547 const char *expected
[] = { "B", "D", "L/1", "a", "c", "e" };
548 size_t expected_len
= 6;
552 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
554 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
555 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
556 git_iterator_free(i
);
559 /* Set no start, but an end. Case INsensitive. */
561 const char *expected
[] = { "a", "B", "c", "D", "e" };
562 size_t expected_len
= 5;
566 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
568 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
569 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
570 git_iterator_free(i
);
573 /* Start and an end, case sensitive */
575 const char *expected
[] = { "c", "e", "k/1" };
576 size_t expected_len
= 3;
580 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
582 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
583 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
584 git_iterator_free(i
);
587 /* Start and an end, case sensitive */
589 const char *expected
[] = { "k/1" };
590 size_t expected_len
= 1;
594 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
596 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
597 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
598 git_iterator_free(i
);
601 /* Start and an end, case INsensitive */
603 const char *expected
[] = { "c", "D", "e", "k/1", "k/a" };
604 size_t expected_len
= 5;
608 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
610 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
611 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
612 git_iterator_free(i
);
615 /* Start and an end, case INsensitive */
617 const char *expected
[] = { "k/1", "k/a" };
618 size_t expected_len
= 2;
622 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
624 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
625 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
626 git_iterator_free(i
);
629 git_index_free(index
);
630 git_vector_free(&filelist
);
633 void test_iterator_index__pathlist_with_dirs(void)
636 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
640 cl_git_pass(git_vector_init(&filelist
, 5, NULL
));
642 g_repo
= cl_git_sandbox_init("icase");
644 cl_git_pass(git_repository_index(&index
, g_repo
));
646 /* Test that a prefix `k` matches folders, even without trailing slash */
648 const char *expected
[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
649 size_t expected_len
= 5;
651 git_vector_clear(&filelist
);
652 cl_git_pass(git_vector_insert(&filelist
, "k"));
654 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
655 i_opts
.pathlist
.count
= filelist
.length
;
656 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
658 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
659 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
660 git_iterator_free(i
);
663 /* Test that a `k/` matches a folder */
665 const char *expected
[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
666 size_t expected_len
= 5;
668 git_vector_clear(&filelist
);
669 cl_git_pass(git_vector_insert(&filelist
, "k/"));
671 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
672 i_opts
.pathlist
.count
= filelist
.length
;
673 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
675 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
676 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
677 git_iterator_free(i
);
680 /* When the iterator is case sensitive, ensure we can't lookup the
681 * directory with the wrong case.
684 git_vector_clear(&filelist
);
685 cl_git_pass(git_vector_insert(&filelist
, "K/"));
687 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
688 i_opts
.pathlist
.count
= filelist
.length
;
689 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
691 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
692 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
693 git_iterator_free(i
);
696 /* Test that case insensitive matching works. */
698 const char *expected
[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
699 size_t expected_len
= 5;
701 git_vector_clear(&filelist
);
702 cl_git_pass(git_vector_insert(&filelist
, "K/"));
704 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
705 i_opts
.pathlist
.count
= filelist
.length
;
706 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
708 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
709 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
710 git_iterator_free(i
);
713 /* Test that case insensitive matching works without trailing slash. */
715 const char *expected
[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
716 size_t expected_len
= 5;
718 git_vector_clear(&filelist
);
719 cl_git_pass(git_vector_insert(&filelist
, "K"));
721 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
722 i_opts
.pathlist
.count
= filelist
.length
;
723 i_opts
.flags
= GIT_ITERATOR_IGNORE_CASE
;
725 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
726 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
727 git_iterator_free(i
);
730 git_index_free(index
);
731 git_vector_free(&filelist
);
734 void test_iterator_index__pathlist_with_dirs_include_trees(void)
737 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
741 const char *expected
[] = { "k/", "k/1", "k/B", "k/D", "k/a", "k/c" };
742 size_t expected_len
= 6;
744 cl_git_pass(git_vector_init(&filelist
, 5, NULL
));
746 g_repo
= cl_git_sandbox_init("icase");
748 cl_git_pass(git_repository_index(&index
, g_repo
));
750 git_vector_clear(&filelist
);
751 cl_git_pass(git_vector_insert(&filelist
, "k"));
753 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
754 i_opts
.pathlist
.count
= filelist
.length
;
755 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
| GIT_ITERATOR_INCLUDE_TREES
;
757 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
758 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
759 git_iterator_free(i
);
761 git_index_free(index
);
762 git_vector_free(&filelist
);
765 void test_iterator_index__pathlist_1(void)
768 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
770 git_vector filelist
= GIT_VECTOR_INIT
;
771 int default_icase
, expect
;
773 g_repo
= cl_git_sandbox_init("icase");
775 cl_git_pass(git_repository_index(&index
, g_repo
));
777 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
778 cl_git_pass(git_vector_insert(&filelist
, "0"));
779 cl_git_pass(git_vector_insert(&filelist
, "c"));
780 cl_git_pass(git_vector_insert(&filelist
, "D"));
781 cl_git_pass(git_vector_insert(&filelist
, "e"));
782 cl_git_pass(git_vector_insert(&filelist
, "k/1"));
783 cl_git_pass(git_vector_insert(&filelist
, "k/a"));
785 /* In this test we DO NOT force a case setting on the index. */
786 default_icase
= ((git_index_caps(index
) & GIT_INDEX_CAPABILITY_IGNORE_CASE
) != 0);
788 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
789 i_opts
.pathlist
.count
= filelist
.length
;
794 /* (c D e k/1 k/a ==> 5) vs (c e k/1 ==> 3) */
795 expect
= default_icase
? 5 : 3;
797 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
798 expect_iterator_items(i
, expect
, NULL
, expect
, NULL
);
799 git_iterator_free(i
);
801 git_index_free(index
);
802 git_vector_free(&filelist
);
805 void test_iterator_index__pathlist_2(void)
808 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
810 git_vector filelist
= GIT_VECTOR_INIT
;
811 int default_icase
, expect
;
813 g_repo
= cl_git_sandbox_init("icase");
815 cl_git_pass(git_repository_index(&index
, g_repo
));
817 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
818 cl_git_pass(git_vector_insert(&filelist
, "0"));
819 cl_git_pass(git_vector_insert(&filelist
, "c"));
820 cl_git_pass(git_vector_insert(&filelist
, "D"));
821 cl_git_pass(git_vector_insert(&filelist
, "e"));
822 cl_git_pass(git_vector_insert(&filelist
, "k/"));
823 cl_git_pass(git_vector_insert(&filelist
, "k.a"));
824 cl_git_pass(git_vector_insert(&filelist
, "k.b"));
825 cl_git_pass(git_vector_insert(&filelist
, "kZZZZZZZ"));
827 /* In this test we DO NOT force a case setting on the index. */
828 default_icase
= ((git_index_caps(index
) & GIT_INDEX_CAPABILITY_IGNORE_CASE
) != 0);
830 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
831 i_opts
.pathlist
.count
= filelist
.length
;
836 /* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
837 expect
= default_icase
? 8 : 5;
839 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
840 expect_iterator_items(i
, expect
, NULL
, expect
, NULL
);
841 git_iterator_free(i
);
843 git_index_free(index
);
844 git_vector_free(&filelist
);
847 void test_iterator_index__pathlist_four(void)
850 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
852 git_vector filelist
= GIT_VECTOR_INIT
;
853 int default_icase
, expect
;
855 g_repo
= cl_git_sandbox_init("icase");
857 cl_git_pass(git_repository_index(&index
, g_repo
));
859 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
860 cl_git_pass(git_vector_insert(&filelist
, "0"));
861 cl_git_pass(git_vector_insert(&filelist
, "c"));
862 cl_git_pass(git_vector_insert(&filelist
, "D"));
863 cl_git_pass(git_vector_insert(&filelist
, "e"));
864 cl_git_pass(git_vector_insert(&filelist
, "k"));
865 cl_git_pass(git_vector_insert(&filelist
, "k.a"));
866 cl_git_pass(git_vector_insert(&filelist
, "k.b"));
867 cl_git_pass(git_vector_insert(&filelist
, "kZZZZZZZ"));
869 /* In this test we DO NOT force a case setting on the index. */
870 default_icase
= ((git_index_caps(index
) & GIT_INDEX_CAPABILITY_IGNORE_CASE
) != 0);
872 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
873 i_opts
.pathlist
.count
= filelist
.length
;
878 /* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
879 expect
= default_icase
? 8 : 5;
881 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
882 expect_iterator_items(i
, expect
, NULL
, expect
, NULL
);
883 git_iterator_free(i
);
885 git_index_free(index
);
886 git_vector_free(&filelist
);
889 void test_iterator_index__pathlist_icase(void)
892 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
897 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
898 cl_git_pass(git_vector_insert(&filelist
, "a"));
899 cl_git_pass(git_vector_insert(&filelist
, "B"));
900 cl_git_pass(git_vector_insert(&filelist
, "c"));
901 cl_git_pass(git_vector_insert(&filelist
, "D"));
902 cl_git_pass(git_vector_insert(&filelist
, "e"));
903 cl_git_pass(git_vector_insert(&filelist
, "k/1"));
904 cl_git_pass(git_vector_insert(&filelist
, "k/a"));
905 cl_git_pass(git_vector_insert(&filelist
, "L/1"));
907 g_repo
= cl_git_sandbox_init("icase");
909 cl_git_pass(git_repository_index(&index
, g_repo
));
910 caps
= git_index_caps(index
);
912 /* force case sensitivity */
913 cl_git_pass(git_index_set_caps(index
, caps
& ~GIT_INDEX_CAPABILITY_IGNORE_CASE
));
915 /* All indexfilelist iterator tests are "autoexpand with no tree entries" */
917 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
918 i_opts
.pathlist
.count
= filelist
.length
;
922 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
923 expect_iterator_items(i
, 3, NULL
, 3, NULL
);
924 git_iterator_free(i
);
928 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
929 expect_iterator_items(i
, 1, NULL
, 1, NULL
);
930 git_iterator_free(i
);
932 /* force case insensitivity */
933 cl_git_pass(git_index_set_caps(index
, caps
| GIT_INDEX_CAPABILITY_IGNORE_CASE
));
937 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
938 expect_iterator_items(i
, 5, NULL
, 5, NULL
);
939 git_iterator_free(i
);
943 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
944 expect_iterator_items(i
, 2, NULL
, 2, NULL
);
945 git_iterator_free(i
);
947 cl_git_pass(git_index_set_caps(index
, caps
));
948 git_index_free(index
);
949 git_vector_free(&filelist
);
952 void test_iterator_index__pathlist_with_directory(void)
955 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
960 g_repo
= cl_git_sandbox_init("testrepo2");
961 git_repository_head_tree(&tree
, g_repo
);
963 cl_git_pass(git_vector_init(&filelist
, 100, &git__strcmp_cb
));
964 cl_git_pass(git_vector_insert(&filelist
, "subdir"));
966 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
967 i_opts
.pathlist
.count
= filelist
.length
;
969 cl_git_pass(git_repository_index(&index
, g_repo
));
970 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
971 expect_iterator_items(i
, 4, NULL
, 4, NULL
);
972 git_iterator_free(i
);
974 git_index_free(index
);
976 git_vector_free(&filelist
);
979 static void create_paths(git_index
*index
, const char *root
, int depth
)
981 git_str fullpath
= GIT_STR_INIT
;
982 git_index_entry entry
;
987 cl_git_pass(git_str_puts(&fullpath
, root
));
988 cl_git_pass(git_str_putc(&fullpath
, '/'));
991 root_len
= fullpath
.size
;
993 for (i
= 0; i
< 8; i
++) {
994 bool file
= (depth
== 0 || (i
% 2) == 0);
995 git_str_truncate(&fullpath
, root_len
);
996 cl_git_pass(git_str_printf(&fullpath
, "item%d", i
));
999 memset(&entry
, 0, sizeof(git_index_entry
));
1000 entry
.path
= fullpath
.ptr
;
1001 entry
.mode
= GIT_FILEMODE_BLOB
;
1002 git_oid_fromstr(&entry
.id
, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
1004 cl_git_pass(git_index_add(index
, &entry
));
1005 } else if (depth
> 0) {
1006 create_paths(index
, fullpath
.ptr
, (depth
- 1));
1010 git_str_dispose(&fullpath
);
1013 void test_iterator_index__pathlist_for_deeply_nested_item(void)
1016 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
1018 git_vector filelist
;
1020 cl_git_pass(git_vector_init(&filelist
, 5, NULL
));
1022 g_repo
= cl_git_sandbox_init("icase");
1023 cl_git_pass(git_repository_index(&index
, g_repo
));
1025 create_paths(index
, NULL
, 3);
1027 /* Ensure that we find the single path we're interested in */
1029 const char *expected
[] = { "item1/item3/item5/item7" };
1030 size_t expected_len
= 1;
1032 git_vector_clear(&filelist
);
1033 cl_git_pass(git_vector_insert(&filelist
, "item1/item3/item5/item7"));
1035 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
1036 i_opts
.pathlist
.count
= filelist
.length
;
1037 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
1039 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1040 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
1041 git_iterator_free(i
);
1045 const char *expected
[] = {
1046 "item1/item3/item5/item0", "item1/item3/item5/item1",
1047 "item1/item3/item5/item2", "item1/item3/item5/item3",
1048 "item1/item3/item5/item4", "item1/item3/item5/item5",
1049 "item1/item3/item5/item6", "item1/item3/item5/item7",
1051 size_t expected_len
= 8;
1053 git_vector_clear(&filelist
);
1054 cl_git_pass(git_vector_insert(&filelist
, "item1/item3/item5/"));
1056 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
1057 i_opts
.pathlist
.count
= filelist
.length
;
1058 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
1060 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1061 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
1062 git_iterator_free(i
);
1066 const char *expected
[] = {
1067 "item1/item3/item0",
1068 "item1/item3/item1/item0", "item1/item3/item1/item1",
1069 "item1/item3/item1/item2", "item1/item3/item1/item3",
1070 "item1/item3/item1/item4", "item1/item3/item1/item5",
1071 "item1/item3/item1/item6", "item1/item3/item1/item7",
1072 "item1/item3/item2",
1073 "item1/item3/item3/item0", "item1/item3/item3/item1",
1074 "item1/item3/item3/item2", "item1/item3/item3/item3",
1075 "item1/item3/item3/item4", "item1/item3/item3/item5",
1076 "item1/item3/item3/item6", "item1/item3/item3/item7",
1077 "item1/item3/item4",
1078 "item1/item3/item5/item0", "item1/item3/item5/item1",
1079 "item1/item3/item5/item2", "item1/item3/item5/item3",
1080 "item1/item3/item5/item4", "item1/item3/item5/item5",
1081 "item1/item3/item5/item6", "item1/item3/item5/item7",
1082 "item1/item3/item6",
1083 "item1/item3/item7/item0", "item1/item3/item7/item1",
1084 "item1/item3/item7/item2", "item1/item3/item7/item3",
1085 "item1/item3/item7/item4", "item1/item3/item7/item5",
1086 "item1/item3/item7/item6", "item1/item3/item7/item7",
1088 size_t expected_len
= 36;
1090 git_vector_clear(&filelist
);
1091 cl_git_pass(git_vector_insert(&filelist
, "item1/item3/"));
1093 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
1094 i_opts
.pathlist
.count
= filelist
.length
;
1095 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
1097 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1098 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
1099 git_iterator_free(i
);
1102 /* Ensure that we find the single path we're interested in, and we find
1103 * it efficiently, and don't stat the entire world to get there.
1106 const char *expected
[] = {
1107 "item0", "item1/item2", "item5/item7/item4", "item6",
1108 "item7/item3/item1/item6" };
1109 size_t expected_len
= 5;
1111 git_vector_clear(&filelist
);
1112 cl_git_pass(git_vector_insert(&filelist
, "item7/item3/item1/item6"));
1113 cl_git_pass(git_vector_insert(&filelist
, "item6"));
1114 cl_git_pass(git_vector_insert(&filelist
, "item5/item7/item4"));
1115 cl_git_pass(git_vector_insert(&filelist
, "item1/item2"));
1116 cl_git_pass(git_vector_insert(&filelist
, "item0"));
1118 /* also add some things that don't exist or don't match the right type */
1119 cl_git_pass(git_vector_insert(&filelist
, "item2/"));
1120 cl_git_pass(git_vector_insert(&filelist
, "itemN"));
1121 cl_git_pass(git_vector_insert(&filelist
, "item1/itemA"));
1122 cl_git_pass(git_vector_insert(&filelist
, "item5/item3/item4/"));
1124 i_opts
.pathlist
.strings
= (char **)filelist
.contents
;
1125 i_opts
.pathlist
.count
= filelist
.length
;
1126 i_opts
.flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
1128 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1129 expect_iterator_items(i
, expected_len
, expected
, expected_len
, expected
);
1130 git_iterator_free(i
);
1133 git_index_free(index
);
1134 git_vector_free(&filelist
);
1137 void test_iterator_index__advance_over(void)
1140 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
1143 i_opts
.flags
|= GIT_ITERATOR_DONT_IGNORE_CASE
|
1144 GIT_ITERATOR_DONT_AUTOEXPAND
;
1146 g_repo
= cl_git_sandbox_init("icase");
1147 cl_git_pass(git_repository_index(&index
, g_repo
));
1149 create_paths(index
, NULL
, 1);
1151 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1153 expect_advance_over(i
, "B", GIT_ITERATOR_STATUS_NORMAL
);
1154 expect_advance_over(i
, "D", GIT_ITERATOR_STATUS_NORMAL
);
1155 expect_advance_over(i
, "F", GIT_ITERATOR_STATUS_NORMAL
);
1156 expect_advance_over(i
, "H", GIT_ITERATOR_STATUS_NORMAL
);
1157 expect_advance_over(i
, "J", GIT_ITERATOR_STATUS_NORMAL
);
1158 expect_advance_over(i
, "L/", GIT_ITERATOR_STATUS_NORMAL
);
1159 expect_advance_over(i
, "a", GIT_ITERATOR_STATUS_NORMAL
);
1160 expect_advance_over(i
, "c", GIT_ITERATOR_STATUS_NORMAL
);
1161 expect_advance_over(i
, "e", GIT_ITERATOR_STATUS_NORMAL
);
1162 expect_advance_over(i
, "g", GIT_ITERATOR_STATUS_NORMAL
);
1163 expect_advance_over(i
, "i", GIT_ITERATOR_STATUS_NORMAL
);
1164 expect_advance_over(i
, "item0", GIT_ITERATOR_STATUS_NORMAL
);
1165 expect_advance_over(i
, "item1/", GIT_ITERATOR_STATUS_NORMAL
);
1166 expect_advance_over(i
, "item2", GIT_ITERATOR_STATUS_NORMAL
);
1167 expect_advance_over(i
, "item3/", GIT_ITERATOR_STATUS_NORMAL
);
1168 expect_advance_over(i
, "item4", GIT_ITERATOR_STATUS_NORMAL
);
1169 expect_advance_over(i
, "item5/", GIT_ITERATOR_STATUS_NORMAL
);
1170 expect_advance_over(i
, "item6", GIT_ITERATOR_STATUS_NORMAL
);
1171 expect_advance_over(i
, "item7/", GIT_ITERATOR_STATUS_NORMAL
);
1172 expect_advance_over(i
, "k/", GIT_ITERATOR_STATUS_NORMAL
);
1174 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
1175 git_iterator_free(i
);
1176 git_index_free(index
);
1179 void test_iterator_index__advance_into(void)
1182 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
1185 g_repo
= cl_git_sandbox_init("icase");
1187 i_opts
.flags
|= GIT_ITERATOR_DONT_IGNORE_CASE
|
1188 GIT_ITERATOR_DONT_AUTOEXPAND
;
1190 cl_git_pass(git_repository_index(&index
, g_repo
));
1192 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1193 expect_advance_into(i
, "B");
1194 expect_advance_into(i
, "D");
1195 expect_advance_into(i
, "F");
1196 expect_advance_into(i
, "H");
1197 expect_advance_into(i
, "J");
1198 expect_advance_into(i
, "L/");
1199 expect_advance_into(i
, "L/1");
1200 expect_advance_into(i
, "L/B");
1201 expect_advance_into(i
, "L/D");
1202 expect_advance_into(i
, "L/a");
1203 expect_advance_into(i
, "L/c");
1204 expect_advance_into(i
, "a");
1205 expect_advance_into(i
, "c");
1206 expect_advance_into(i
, "e");
1207 expect_advance_into(i
, "g");
1208 expect_advance_into(i
, "i");
1209 expect_advance_into(i
, "k/");
1210 expect_advance_into(i
, "k/1");
1211 expect_advance_into(i
, "k/B");
1212 expect_advance_into(i
, "k/D");
1213 expect_advance_into(i
, "k/a");
1214 expect_advance_into(i
, "k/c");
1216 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
1217 git_iterator_free(i
);
1218 git_index_free(index
);
1221 void test_iterator_index__advance_into_and_over(void)
1224 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
1227 g_repo
= cl_git_sandbox_init("icase");
1229 i_opts
.flags
|= GIT_ITERATOR_DONT_IGNORE_CASE
|
1230 GIT_ITERATOR_DONT_AUTOEXPAND
;
1232 cl_git_pass(git_repository_index(&index
, g_repo
));
1234 create_paths(index
, NULL
, 2);
1236 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1237 expect_advance_into(i
, "B");
1238 expect_advance_into(i
, "D");
1239 expect_advance_into(i
, "F");
1240 expect_advance_into(i
, "H");
1241 expect_advance_into(i
, "J");
1242 expect_advance_into(i
, "L/");
1243 expect_advance_into(i
, "L/1");
1244 expect_advance_into(i
, "L/B");
1245 expect_advance_into(i
, "L/D");
1246 expect_advance_into(i
, "L/a");
1247 expect_advance_into(i
, "L/c");
1248 expect_advance_into(i
, "a");
1249 expect_advance_into(i
, "c");
1250 expect_advance_into(i
, "e");
1251 expect_advance_into(i
, "g");
1252 expect_advance_into(i
, "i");
1253 expect_advance_into(i
, "item0");
1254 expect_advance_into(i
, "item1/");
1255 expect_advance_into(i
, "item1/item0");
1256 expect_advance_into(i
, "item1/item1/");
1257 expect_advance_into(i
, "item1/item1/item0");
1258 expect_advance_into(i
, "item1/item1/item1");
1259 expect_advance_into(i
, "item1/item1/item2");
1260 expect_advance_into(i
, "item1/item1/item3");
1261 expect_advance_into(i
, "item1/item1/item4");
1262 expect_advance_into(i
, "item1/item1/item5");
1263 expect_advance_into(i
, "item1/item1/item6");
1264 expect_advance_into(i
, "item1/item1/item7");
1265 expect_advance_into(i
, "item1/item2");
1266 expect_advance_over(i
, "item1/item3/", GIT_ITERATOR_STATUS_NORMAL
);
1267 expect_advance_over(i
, "item1/item4", GIT_ITERATOR_STATUS_NORMAL
);
1268 expect_advance_over(i
, "item1/item5/", GIT_ITERATOR_STATUS_NORMAL
);
1269 expect_advance_over(i
, "item1/item6", GIT_ITERATOR_STATUS_NORMAL
);
1270 expect_advance_over(i
, "item1/item7/", GIT_ITERATOR_STATUS_NORMAL
);
1271 expect_advance_into(i
, "item2");
1272 expect_advance_over(i
, "item3/", GIT_ITERATOR_STATUS_NORMAL
);
1273 expect_advance_over(i
, "item4", GIT_ITERATOR_STATUS_NORMAL
);
1274 expect_advance_over(i
, "item5/", GIT_ITERATOR_STATUS_NORMAL
);
1275 expect_advance_over(i
, "item6", GIT_ITERATOR_STATUS_NORMAL
);
1276 expect_advance_over(i
, "item7/", GIT_ITERATOR_STATUS_NORMAL
);
1277 expect_advance_into(i
, "k/");
1278 expect_advance_into(i
, "k/1");
1279 expect_advance_into(i
, "k/B");
1280 expect_advance_into(i
, "k/D");
1281 expect_advance_into(i
, "k/a");
1282 expect_advance_into(i
, "k/c");
1284 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
1285 git_iterator_free(i
);
1286 git_index_free(index
);
1289 static void add_conflict(
1291 const char *ancestor_path
,
1292 const char *our_path
,
1293 const char *their_path
)
1295 git_index_entry ancestor
= {{0}}, ours
= {{0}}, theirs
= {{0}};
1297 ancestor
.path
= ancestor_path
;
1298 ancestor
.mode
= GIT_FILEMODE_BLOB
;
1299 git_oid_fromstr(&ancestor
.id
, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
1300 GIT_INDEX_ENTRY_STAGE_SET(&ancestor
, 1);
1302 ours
.path
= our_path
;
1303 ours
.mode
= GIT_FILEMODE_BLOB
;
1304 git_oid_fromstr(&ours
.id
, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
1305 GIT_INDEX_ENTRY_STAGE_SET(&ours
, 2);
1307 theirs
.path
= their_path
;
1308 theirs
.mode
= GIT_FILEMODE_BLOB
;
1309 git_oid_fromstr(&theirs
.id
, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
1310 GIT_INDEX_ENTRY_STAGE_SET(&theirs
, 3);
1312 cl_git_pass(git_index_conflict_add(index
, &ancestor
, &ours
, &theirs
));
1315 void test_iterator_index__include_conflicts(void)
1318 git_iterator_options i_opts
= GIT_ITERATOR_OPTIONS_INIT
;
1321 i_opts
.flags
|= GIT_ITERATOR_DONT_IGNORE_CASE
|
1322 GIT_ITERATOR_DONT_AUTOEXPAND
;
1324 g_repo
= cl_git_sandbox_init("icase");
1325 cl_git_pass(git_repository_index(&index
, g_repo
));
1327 add_conflict(index
, "CONFLICT1", "CONFLICT1" ,"CONFLICT1");
1328 add_conflict(index
, "ZZZ-CONFLICT2.ancestor", "ZZZ-CONFLICT2.ours", "ZZZ-CONFLICT2.theirs");
1329 add_conflict(index
, "ancestor.conflict3", "ours.conflict3", "theirs.conflict3");
1330 add_conflict(index
, "zzz-conflict4", "zzz-conflict4", "zzz-conflict4");
1332 /* Iterate the index, ensuring that conflicts are not included */
1333 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1335 expect_advance_over(i
, "B", GIT_ITERATOR_STATUS_NORMAL
);
1336 expect_advance_over(i
, "D", GIT_ITERATOR_STATUS_NORMAL
);
1337 expect_advance_over(i
, "F", GIT_ITERATOR_STATUS_NORMAL
);
1338 expect_advance_over(i
, "H", GIT_ITERATOR_STATUS_NORMAL
);
1339 expect_advance_over(i
, "J", GIT_ITERATOR_STATUS_NORMAL
);
1340 expect_advance_over(i
, "L/", GIT_ITERATOR_STATUS_NORMAL
);
1341 expect_advance_over(i
, "a", GIT_ITERATOR_STATUS_NORMAL
);
1342 expect_advance_over(i
, "c", GIT_ITERATOR_STATUS_NORMAL
);
1343 expect_advance_over(i
, "e", GIT_ITERATOR_STATUS_NORMAL
);
1344 expect_advance_over(i
, "g", GIT_ITERATOR_STATUS_NORMAL
);
1345 expect_advance_over(i
, "i", GIT_ITERATOR_STATUS_NORMAL
);
1346 expect_advance_over(i
, "k/", GIT_ITERATOR_STATUS_NORMAL
);
1348 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
1349 git_iterator_free(i
);
1351 /* Try again, returning conflicts */
1352 i_opts
.flags
|= GIT_ITERATOR_INCLUDE_CONFLICTS
;
1354 cl_git_pass(git_iterator_for_index(&i
, g_repo
, index
, &i_opts
));
1356 expect_advance_over(i
, "B", GIT_ITERATOR_STATUS_NORMAL
);
1357 expect_advance_over(i
, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL
);
1358 expect_advance_over(i
, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL
);
1359 expect_advance_over(i
, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL
);
1360 expect_advance_over(i
, "D", GIT_ITERATOR_STATUS_NORMAL
);
1361 expect_advance_over(i
, "F", GIT_ITERATOR_STATUS_NORMAL
);
1362 expect_advance_over(i
, "H", GIT_ITERATOR_STATUS_NORMAL
);
1363 expect_advance_over(i
, "J", GIT_ITERATOR_STATUS_NORMAL
);
1364 expect_advance_over(i
, "L/", GIT_ITERATOR_STATUS_NORMAL
);
1365 expect_advance_over(i
, "ZZZ-CONFLICT2.ancestor", GIT_ITERATOR_STATUS_NORMAL
);
1366 expect_advance_over(i
, "ZZZ-CONFLICT2.ours", GIT_ITERATOR_STATUS_NORMAL
);
1367 expect_advance_over(i
, "ZZZ-CONFLICT2.theirs", GIT_ITERATOR_STATUS_NORMAL
);
1368 expect_advance_over(i
, "a", GIT_ITERATOR_STATUS_NORMAL
);
1369 expect_advance_over(i
, "ancestor.conflict3", GIT_ITERATOR_STATUS_NORMAL
);
1370 expect_advance_over(i
, "c", GIT_ITERATOR_STATUS_NORMAL
);
1371 expect_advance_over(i
, "e", GIT_ITERATOR_STATUS_NORMAL
);
1372 expect_advance_over(i
, "g", GIT_ITERATOR_STATUS_NORMAL
);
1373 expect_advance_over(i
, "i", GIT_ITERATOR_STATUS_NORMAL
);
1374 expect_advance_over(i
, "k/", GIT_ITERATOR_STATUS_NORMAL
);
1375 expect_advance_over(i
, "ours.conflict3", GIT_ITERATOR_STATUS_NORMAL
);
1376 expect_advance_over(i
, "theirs.conflict3", GIT_ITERATOR_STATUS_NORMAL
);
1377 expect_advance_over(i
, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL
);
1378 expect_advance_over(i
, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL
);
1379 expect_advance_over(i
, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL
);
1381 cl_git_fail_with(GIT_ITEROVER
, git_iterator_advance(NULL
, i
));
1382 git_iterator_free(i
);
1384 git_index_free(index
);