Blame tests/iterator/index.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "iterator.h"
Packit Service 20376f
#include "repository.h"
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
#include "iterator_helpers.h"
Packit Service 20376f
#include "../submodule/submodule_helpers.h"
Packit Service 20376f
#include <stdarg.h>
Packit Service 20376f
Packit Service 20376f
static git_repository *g_repo;
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
	g_repo = NULL;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void index_iterator_test(
Packit Service 20376f
	const char *sandbox,
Packit Service 20376f
	const char *start,
Packit Service 20376f
	const char *end,
Packit Service 20376f
	git_iterator_flag_t flags,
Packit Service 20376f
	int expected_count,
Packit Service 20376f
	const char **expected_names,
Packit Service 20376f
	const char **expected_oids)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	const git_index_entry *entry;
Packit Service 20376f
	int error, count = 0, caps;
Packit Service 20376f
	git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init(sandbox);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	caps = git_index_caps(index);
Packit Service 20376f
Packit Service 20376f
	iter_opts.flags = flags;
Packit Service 20376f
	iter_opts.start = start;
Packit Service 20376f
	iter_opts.end = end;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &iter_opts));
Packit Service 20376f
Packit Service 20376f
	while (!(error = git_iterator_advance(&entry, i))) {
Packit Service 20376f
		cl_assert(entry);
Packit Service 20376f
Packit Service 20376f
		if (expected_names != NULL)
Packit Service 20376f
			cl_assert_equal_s(expected_names[count], entry->path);
Packit Service 20376f
Packit Service 20376f
		if (expected_oids != NULL) {
Packit Service 20376f
			git_oid oid;
Packit Service 20376f
			cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
Packit Service 20376f
			cl_assert_equal_oid(&oid, &entry->id);
Packit Service 20376f
		}
Packit Service 20376f
Packit Service 20376f
		count++;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(GIT_ITEROVER, error);
Packit Service 20376f
	cl_assert(!entry);
Packit Service 20376f
	cl_assert_equal_i(expected_count, count);
Packit Service 20376f
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	cl_assert(caps == git_index_caps(index));
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_0[] = {
Packit Service 20376f
	"attr0",
Packit Service 20376f
	"attr1",
Packit Service 20376f
	"attr2",
Packit Service 20376f
	"attr3",
Packit Service 20376f
	"binfile",
Packit Service 20376f
	"gitattributes",
Packit Service 20376f
	"macro_bad",
Packit Service 20376f
	"macro_test",
Packit Service 20376f
	"root_test1",
Packit Service 20376f
	"root_test2",
Packit Service 20376f
	"root_test3",
Packit Service 20376f
	"root_test4.txt",
Packit Service 20376f
	"sub/abc",
Packit Service 20376f
	"sub/file",
Packit Service 20376f
	"sub/sub/file",
Packit Service 20376f
	"sub/sub/subsub.txt",
Packit Service 20376f
	"sub/subdir_test1",
Packit Service 20376f
	"sub/subdir_test2.txt",
Packit Service 20376f
	"subdir/.gitattributes",
Packit Service 20376f
	"subdir/abc",
Packit Service 20376f
	"subdir/subdir_test1",
Packit Service 20376f
	"subdir/subdir_test2.txt",
Packit Service 20376f
	"subdir2/subdir2_test1",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_oids_0[] = {
Packit Service 20376f
	"556f8c827b8e4a02ad5cab77dca2bcb3e226b0b3",
Packit Service 20376f
	"3b74db7ab381105dc0d28f8295a77f6a82989292",
Packit Service 20376f
	"2c66e14f77196ea763fb1e41612c1aa2bc2d8ed2",
Packit Service 20376f
	"c485abe35abd4aa6fd83b076a78bbea9e2e7e06c",
Packit Service 20376f
	"d800886d9c86731ae5c4a62b0b77c437015e00d2",
Packit Service 20376f
	"2b40c5aca159b04ea8d20ffe36cdf8b09369b14a",
Packit Service 20376f
	"5819a185d77b03325aaf87cafc771db36f6ddca7",
Packit Service 20376f
	"ff69f8639ce2e6010b3f33a74160aad98b48da2b",
Packit Service 20376f
	"45141a79a77842c59a63229403220a4e4be74e3d",
Packit Service 20376f
	"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
Packit Service 20376f
	"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
Packit Service 20376f
	"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
Packit Service 20376f
	"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
Packit Service 20376f
	"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
Packit Service 20376f
	"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
Packit Service 20376f
	"9e5bdc47d6a80f2be0ea3049ad74231b94609242",
Packit Service 20376f
	"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
Packit Service 20376f
	"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
Packit Service 20376f
	"99eae476896f4907224978b88e5ecaa6c5bb67a9",
Packit Service 20376f
	"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
Packit Service 20376f
	"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
Packit Service 20376f
	"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
Packit Service 20376f
	"dccada462d3df8ac6de596fb8c896aba9344f941"
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__0(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"attr", NULL, NULL, 0, ARRAY_SIZE(expected_index_0),
Packit Service 20376f
		expected_index_0, expected_index_oids_0);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_1[] = {
Packit Service 20376f
	"current_file",
Packit Service 20376f
	"file_deleted",
Packit Service 20376f
	"modified_file",
Packit Service 20376f
	"staged_changes",
Packit Service 20376f
	"staged_changes_file_deleted",
Packit Service 20376f
	"staged_changes_modified_file",
Packit Service 20376f
	"staged_new_file",
Packit Service 20376f
	"staged_new_file_deleted_file",
Packit Service 20376f
	"staged_new_file_modified_file",
Packit Service 20376f
	"subdir.txt",
Packit Service 20376f
	"subdir/current_file",
Packit Service 20376f
	"subdir/deleted_file",
Packit Service 20376f
	"subdir/modified_file",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static const char* expected_index_oids_1[] = {
Packit Service 20376f
	"a0de7e0ac200c489c41c59dfa910154a70264e6e",
Packit Service 20376f
	"5452d32f1dd538eb0405e8a83cc185f79e25e80f",
Packit Service 20376f
	"452e4244b5d083ddf0460acf1ecc74db9dcfa11a",
Packit Service 20376f
	"55d316c9ba708999f1918e9677d01dfcae69c6b9",
Packit Service 20376f
	"a6be623522ce87a1d862128ac42672604f7b468b",
Packit Service 20376f
	"906ee7711f4f4928ddcb2a5f8fbc500deba0d2a8",
Packit Service 20376f
	"529a16e8e762d4acb7b9636ff540a00831f9155a",
Packit Service 20376f
	"90b8c29d8ba39434d1c63e1b093daaa26e5bd972",
Packit Service 20376f
	"ed062903b8f6f3dccb2fa81117ba6590944ef9bd",
Packit Service 20376f
	"e8ee89e15bbe9b20137715232387b3de5b28972e",
Packit Service 20376f
	"53ace0d1cc1145a5f4fe4f78a186a60263190733",
Packit Service 20376f
	"1888c805345ba265b0ee9449b8877b6064592058",
Packit Service 20376f
	"a6191982709b746d5650e93c2acf34ef74e11504"
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__1(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"status", NULL, NULL, 0, ARRAY_SIZE(expected_index_1),
Packit Service 20376f
		expected_index_1, expected_index_oids_1);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_range[] = {
Packit Service 20376f
	"root_test1",
Packit Service 20376f
	"root_test2",
Packit Service 20376f
	"root_test3",
Packit Service 20376f
	"root_test4.txt",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_oids_range[] = {
Packit Service 20376f
	"45141a79a77842c59a63229403220a4e4be74e3d",
Packit Service 20376f
	"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
Packit Service 20376f
	"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
Packit Service 20376f
	"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__range(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"attr", "root", "root", 0, ARRAY_SIZE(expected_index_range),
Packit Service 20376f
		expected_index_range, expected_index_oids_range);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__range_empty_0(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"attr", "empty", "empty", 0, 0, NULL, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__range_empty_1(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"attr", "z_empty_after", NULL, 0, 0, NULL, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__range_empty_2(void)
Packit Service 20376f
{
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"attr", NULL, ".aaa_empty_before", 0, 0, NULL, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void check_index_range(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *start,
Packit Service 20376f
	const char *end,
Packit Service 20376f
	bool ignore_case,
Packit Service 20376f
	int expected_count)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	int error, count, caps;
Packit Service 20376f
	bool is_ignoring_case;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, repo));
Packit Service 20376f
Packit Service 20376f
	caps = git_index_caps(index);
Packit Service 20376f
	is_ignoring_case = ((caps & GIT_INDEXCAP_IGNORE_CASE) != 0);
Packit Service 20376f
Packit Service 20376f
	if (ignore_case != is_ignoring_case)
Packit Service 20376f
		cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
Packit Service 20376f
Packit Service 20376f
	i_opts.flags = 0;
Packit Service 20376f
	i_opts.start = start;
Packit Service 20376f
	i_opts.end = end;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, repo, index, &i_opts));
Packit Service 20376f
Packit Service 20376f
	cl_assert(git_iterator_ignore_case(i) == ignore_case);
Packit Service 20376f
Packit Service 20376f
	for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
Packit Service 20376f
		/* count em up */;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(GIT_ITEROVER, error);
Packit Service 20376f
	cl_assert_equal_i(expected_count, count);
Packit Service 20376f
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__range_icase(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_tree *head;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("testrepo");
Packit Service 20376f
Packit Service 20376f
	/* reset index to match HEAD */
Packit Service 20376f
	cl_git_pass(git_repository_head_tree(&head, g_repo));
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	cl_git_pass(git_index_read_tree(index, head));
Packit Service 20376f
	cl_git_pass(git_index_write(index));
Packit Service 20376f
	git_tree_free(head);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
Packit Service 20376f
	/* do some ranged iterator checks toggling case sensitivity */
Packit Service 20376f
	check_index_range(g_repo, "B", "C", false, 0);
Packit Service 20376f
	check_index_range(g_repo, "B", "C", true, 1);
Packit Service 20376f
	check_index_range(g_repo, "a", "z", false, 3);
Packit Service 20376f
	check_index_range(g_repo, "a", "z", true, 4);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_cs[] = {
Packit Service 20376f
	"B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
Packit Service 20376f
	"a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static const char *expected_index_ci[] = {
Packit Service 20376f
	"a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
Packit Service 20376f
	"k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__case_folding(void)
Packit Service 20376f
{
Packit Service 20376f
	git_buf path = GIT_BUF_INIT;
Packit Service 20376f
	int fs_is_ci = 0;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
Packit Service 20376f
	fs_is_ci = git_path_exists(path.ptr);
Packit Service 20376f
	git_buf_free(&path);
Packit Service 20376f
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
Packit Service 20376f
		fs_is_ci ? expected_index_ci : expected_index_cs, NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"icase", NULL, NULL, GIT_ITERATOR_IGNORE_CASE,
Packit Service 20376f
		ARRAY_SIZE(expected_index_ci), expected_index_ci, NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
Packit Service 20376f
	index_iterator_test(
Packit Service 20376f
		"icase", NULL, NULL, GIT_ITERATOR_DONT_IGNORE_CASE,
Packit Service 20376f
		ARRAY_SIZE(expected_index_cs), expected_index_cs, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/* Index contents (including pseudotrees):
Packit Service 20376f
 *
Packit Service 20376f
 * 0: a     5: F     10: k/      16: L/
Packit Service 20376f
 * 1: B     6: g     11: k/1     17: L/1
Packit Service 20376f
 * 2: c     7: H     12: k/a     18: L/a
Packit Service 20376f
 * 3: D     8: i     13: k/B     19: L/B
Packit Service 20376f
 * 4: e     9: J     14: k/c     20: L/c
Packit Service 20376f
 *                   15: k/D     21: L/D
Packit Service 20376f
 *
Packit Service 20376f
 * 0: B     5: L/    11: a       16: k/
Packit Service 20376f
 * 1: D     6: L/1   12: c       17: k/1
Packit Service 20376f
 * 2: F     7: L/B   13: e       18: k/B
Packit Service 20376f
 * 3: H     8: L/D   14: g       19: k/D
Packit Service 20376f
 * 4: J     9: L/a   15: i       20: k/a
Packit Service 20376f
 *         10: L/c               21: k/c
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__icase_0(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	/* autoexpand with no tree entries for index */
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, NULL));
Packit Service 20376f
	expect_iterator_items(i, 20, NULL, 20, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* auto expand with tree entries */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 22, NULL, 22, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* no auto expand (implies trees included) */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 12, NULL, 22, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__icase_1(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	int caps;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	caps = git_index_caps(index);
Packit Service 20376f
Packit Service 20376f
	/* force case sensitivity */
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
Packit Service 20376f
Packit Service 20376f
	/* autoexpand with no tree entries over range */
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 7, NULL, 7, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 3, NULL, 3, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* auto expand with tree entries */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 8, NULL, 8, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 4, NULL, 4, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* no auto expand (implies trees included) */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 5, NULL, 8, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 1, NULL, 4, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* force case insensitivity */
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
Packit Service 20376f
Packit Service 20376f
	/* autoexpand with no tree entries over range */
Packit Service 20376f
	i_opts.flags = 0;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 13, NULL, 13, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 5, NULL, 5, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* auto expand with tree entries */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 14, NULL, 14, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 6, NULL, 6, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* no auto expand (implies trees included) */
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 9, NULL, 14, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 1, NULL, 6, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps));
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "B"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "c"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "D"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "e"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/1"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "L/1"));
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	/* Case sensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = {
Packit Service 20376f
			"B", "D", "L/1", "a", "c", "e", "k/1", "k/a" };
Packit Service 20376f
		size_t expected_len = 8;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = NULL;
Packit Service 20376f
		i_opts.end = NULL;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Case INsensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = {
Packit Service 20376f
			"a", "B", "c", "D", "e", "k/1", "k/a", "L/1" };
Packit Service 20376f
		size_t expected_len = 8;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = NULL;
Packit Service 20376f
		i_opts.end = NULL;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Set a start, but no end.  Case sensitive. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "c", "e", "k/1", "k/a" };
Packit Service 20376f
		size_t expected_len = 4;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "c";
Packit Service 20376f
		i_opts.end = NULL;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Set a start, but no end.  Case INsensitive. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "c", "D", "e", "k/1", "k/a", "L/1" };
Packit Service 20376f
		size_t expected_len = 6;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "c";
Packit Service 20376f
		i_opts.end = NULL;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Set no start, but an end.  Case sensitive. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "B", "D", "L/1", "a", "c", "e" };
Packit Service 20376f
		size_t expected_len = 6;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = NULL;
Packit Service 20376f
		i_opts.end = "e";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Set no start, but an end.  Case INsensitive. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "a", "B", "c", "D", "e" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = NULL;
Packit Service 20376f
		i_opts.end = "e";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Start and an end, case sensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "c", "e", "k/1" };
Packit Service 20376f
		size_t expected_len = 3;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "c";
Packit Service 20376f
		i_opts.end = "k/D";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Start and an end, case sensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1" };
Packit Service 20376f
		size_t expected_len = 1;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "k";
Packit Service 20376f
		i_opts.end = "k/D";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Start and an end, case INsensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "c", "D", "e", "k/1", "k/a" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "c";
Packit Service 20376f
		i_opts.end = "k/D";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Start and an end, case INsensitive */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1", "k/a" };
Packit Service 20376f
		size_t expected_len = 2;
Packit Service 20376f
Packit Service 20376f
		i_opts.start = "k";
Packit Service 20376f
		i_opts.end = "k/D";
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_with_dirs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 5, NULL));
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	/* Test that a prefix `k` matches folders, even without trailing slash */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "k"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Test that a `k/` matches a folder */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "k/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* When the iterator is case sensitive, ensure we can't lookup the
Packit Service 20376f
	 * directory with the wrong case.
Packit Service 20376f
	 */
Packit Service 20376f
	{
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "K/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Test that case insensitive matching works. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "K/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Test that case insensitive matching works without trailing slash. */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "K"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_with_dirs_include_trees(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
Packit Service 20376f
	const char *expected[] = { "k/", "k/1", "k/B", "k/D", "k/a", "k/c" };
Packit Service 20376f
	size_t expected_len = 6;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 5, NULL));
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	git_vector_clear(&filelist);
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k"));
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
	i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_1(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist = GIT_VECTOR_INIT;
Packit Service 20376f
	int default_icase, expect;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "0"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "c"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "D"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "e"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/1"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/a"));
Packit Service 20376f
Packit Service 20376f
	/* In this test we DO NOT force a case setting on the index. */
Packit Service 20376f
	default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "b";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
Packit Service 20376f
	/* (c D e k/1 k/a ==> 5) vs (c e k/1 ==> 3) */
Packit Service 20376f
	expect = default_icase ? 5 : 3;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, expect, NULL, expect, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_2(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist = GIT_VECTOR_INIT;
Packit Service 20376f
	int default_icase, expect;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "0"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "c"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "D"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "e"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k.a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k.b"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
Packit Service 20376f
Packit Service 20376f
	/* In this test we DO NOT force a case setting on the index. */
Packit Service 20376f
	default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "b";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
Packit Service 20376f
	/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
Packit Service 20376f
	expect = default_icase ? 8 : 5;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, expect, NULL, expect, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_four(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist = GIT_VECTOR_INIT;
Packit Service 20376f
	int default_icase, expect;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "0"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "c"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "D"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "e"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k.a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k.b"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
Packit Service 20376f
Packit Service 20376f
	/* In this test we DO NOT force a case setting on the index. */
Packit Service 20376f
	default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "b";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
Packit Service 20376f
	/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
Packit Service 20376f
	expect = default_icase ? 8 : 5;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, expect, NULL, expect, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_icase(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	int caps;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "B"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "c"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "D"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "e"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/1"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "k/a"));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "L/1"));
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	caps = git_index_caps(index);
Packit Service 20376f
Packit Service 20376f
	/* force case sensitivity */
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
Packit Service 20376f
Packit Service 20376f
	/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 3, NULL, 3, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 1, NULL, 1, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* force case insensitivity */
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "c";
Packit Service 20376f
	i_opts.end = "k/D";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 5, NULL, 5, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	i_opts.start = "k";
Packit Service 20376f
	i_opts.end = "k/Z";
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 2, NULL, 2, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_set_caps(index, caps));
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_with_directory(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
	git_tree *tree;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("testrepo2");
Packit Service 20376f
	git_repository_head_tree(&tree, g_repo);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
Packit Service 20376f
	cl_git_pass(git_vector_insert(&filelist, "subdir"));
Packit Service 20376f
Packit Service 20376f
	i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
	i_opts.pathlist.count = filelist.length;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_iterator_items(i, 4, NULL, 4, NULL);
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_tree_free(tree);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void create_paths(git_index *index, const char *root, int depth)
Packit Service 20376f
{
Packit Service 20376f
	git_buf fullpath = GIT_BUF_INIT;
Packit Service 20376f
	git_index_entry entry;
Packit Service 20376f
	size_t root_len;
Packit Service 20376f
	int i;
Packit Service 20376f
Packit Service 20376f
	if (root) {
Packit Service 20376f
		cl_git_pass(git_buf_puts(&fullpath, root));
Packit Service 20376f
		cl_git_pass(git_buf_putc(&fullpath, '/'));
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	root_len = fullpath.size;
Packit Service 20376f
Packit Service 20376f
	for (i = 0; i < 8; i++) {
Packit Service 20376f
		bool file = (depth == 0 || (i % 2) == 0);
Packit Service 20376f
		git_buf_truncate(&fullpath, root_len);
Packit Service 20376f
		cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
Packit Service 20376f
Packit Service 20376f
		if (file) {
Packit Service 20376f
			memset(&entry, 0, sizeof(git_index_entry));
Packit Service 20376f
			entry.path = fullpath.ptr;
Packit Service 20376f
			entry.mode = GIT_FILEMODE_BLOB;
Packit Service 20376f
			git_oid_fromstr(&entry.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
Packit Service 20376f
Packit Service 20376f
			cl_git_pass(git_index_add(index, &entry));
Packit Service 20376f
		} else if (depth > 0) {
Packit Service 20376f
			create_paths(index, fullpath.ptr, (depth - 1));
Packit Service 20376f
		}
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	git_buf_free(&fullpath);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__pathlist_for_deeply_nested_item(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_vector filelist;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_vector_init(&filelist, 5, NULL));
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	create_paths(index, NULL, 3);
Packit Service 20376f
Packit Service 20376f
	/* Ensure that we find the single path we're interested in */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = { "item1/item3/item5/item7" };
Packit Service 20376f
		size_t expected_len = 1;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/item7"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = {
Packit Service 20376f
			"item1/item3/item5/item0", "item1/item3/item5/item1",
Packit Service 20376f
			"item1/item3/item5/item2", "item1/item3/item5/item3",
Packit Service 20376f
			"item1/item3/item5/item4", "item1/item3/item5/item5",
Packit Service 20376f
			"item1/item3/item5/item6", "item1/item3/item5/item7",
Packit Service 20376f
		};
Packit Service 20376f
		size_t expected_len = 8;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = {
Packit Service 20376f
			"item1/item3/item0",
Packit Service 20376f
			"item1/item3/item1/item0", "item1/item3/item1/item1",
Packit Service 20376f
			"item1/item3/item1/item2", "item1/item3/item1/item3",
Packit Service 20376f
			"item1/item3/item1/item4", "item1/item3/item1/item5",
Packit Service 20376f
			"item1/item3/item1/item6", "item1/item3/item1/item7",
Packit Service 20376f
			"item1/item3/item2",
Packit Service 20376f
			"item1/item3/item3/item0", "item1/item3/item3/item1",
Packit Service 20376f
			"item1/item3/item3/item2", "item1/item3/item3/item3",
Packit Service 20376f
			"item1/item3/item3/item4", "item1/item3/item3/item5",
Packit Service 20376f
			"item1/item3/item3/item6", "item1/item3/item3/item7",
Packit Service 20376f
			"item1/item3/item4",
Packit Service 20376f
			"item1/item3/item5/item0", "item1/item3/item5/item1",
Packit Service 20376f
			"item1/item3/item5/item2", "item1/item3/item5/item3",
Packit Service 20376f
			"item1/item3/item5/item4", "item1/item3/item5/item5",
Packit Service 20376f
			"item1/item3/item5/item6", "item1/item3/item5/item7",
Packit Service 20376f
			"item1/item3/item6",
Packit Service 20376f
			"item1/item3/item7/item0", "item1/item3/item7/item1",
Packit Service 20376f
			"item1/item3/item7/item2", "item1/item3/item7/item3",
Packit Service 20376f
			"item1/item3/item7/item4", "item1/item3/item7/item5",
Packit Service 20376f
			"item1/item3/item7/item6", "item1/item3/item7/item7",
Packit Service 20376f
		};
Packit Service 20376f
		size_t expected_len = 36;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item1/item3/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	/* Ensure that we find the single path we're interested in, and we find
Packit Service 20376f
	 * it efficiently, and don't stat the entire world to get there.
Packit Service 20376f
	 */
Packit Service 20376f
	{
Packit Service 20376f
		const char *expected[] = {
Packit Service 20376f
			"item0", "item1/item2", "item5/item7/item4", "item6",
Packit Service 20376f
			"item7/item3/item1/item6" };
Packit Service 20376f
		size_t expected_len = 5;
Packit Service 20376f
Packit Service 20376f
		git_vector_clear(&filelist);
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item7/item3/item1/item6"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item6"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item5/item7/item4"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item1/item2"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item0"));
Packit Service 20376f
Packit Service 20376f
		/* also add some things that don't exist or don't match the right type */
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item2/"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "itemN"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item1/itemA"));
Packit Service 20376f
		cl_git_pass(git_vector_insert(&filelist, "item5/item3/item4/"));
Packit Service 20376f
Packit Service 20376f
		i_opts.pathlist.strings = (char **)filelist.contents;
Packit Service 20376f
		i_opts.pathlist.count = filelist.length;
Packit Service 20376f
		i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
Packit Service 20376f
Packit Service 20376f
		cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
		expect_iterator_items(i, expected_len, expected, expected_len, expected);
Packit Service 20376f
		git_iterator_free(i);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
	git_vector_free(&filelist);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__advance_over(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
Packit Service 20376f
		GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	create_paths(index, NULL, 1);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
Packit Service 20376f
	expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item0", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item1/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item2", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item3/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item5/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item6", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item7/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__advance_into(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
Packit Service 20376f
		GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_advance_into(i, "B");
Packit Service 20376f
	expect_advance_into(i, "D");
Packit Service 20376f
	expect_advance_into(i, "F");
Packit Service 20376f
	expect_advance_into(i, "H");
Packit Service 20376f
	expect_advance_into(i, "J");
Packit Service 20376f
	expect_advance_into(i, "L/");
Packit Service 20376f
	expect_advance_into(i, "L/1");
Packit Service 20376f
	expect_advance_into(i, "L/B");
Packit Service 20376f
	expect_advance_into(i, "L/D");
Packit Service 20376f
	expect_advance_into(i, "L/a");
Packit Service 20376f
	expect_advance_into(i, "L/c");
Packit Service 20376f
	expect_advance_into(i, "a");
Packit Service 20376f
	expect_advance_into(i, "c");
Packit Service 20376f
	expect_advance_into(i, "e");
Packit Service 20376f
	expect_advance_into(i, "g");
Packit Service 20376f
	expect_advance_into(i, "i");
Packit Service 20376f
	expect_advance_into(i, "k/");
Packit Service 20376f
	expect_advance_into(i, "k/1");
Packit Service 20376f
	expect_advance_into(i, "k/B");
Packit Service 20376f
	expect_advance_into(i, "k/D");
Packit Service 20376f
	expect_advance_into(i, "k/a");
Packit Service 20376f
	expect_advance_into(i, "k/c");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__advance_into_and_over(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
Packit Service 20376f
	i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
Packit Service 20376f
	GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	create_paths(index, NULL, 2);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
	expect_advance_into(i, "B");
Packit Service 20376f
	expect_advance_into(i, "D");
Packit Service 20376f
	expect_advance_into(i, "F");
Packit Service 20376f
	expect_advance_into(i, "H");
Packit Service 20376f
	expect_advance_into(i, "J");
Packit Service 20376f
	expect_advance_into(i, "L/");
Packit Service 20376f
	expect_advance_into(i, "L/1");
Packit Service 20376f
	expect_advance_into(i, "L/B");
Packit Service 20376f
	expect_advance_into(i, "L/D");
Packit Service 20376f
	expect_advance_into(i, "L/a");
Packit Service 20376f
	expect_advance_into(i, "L/c");
Packit Service 20376f
	expect_advance_into(i, "a");
Packit Service 20376f
	expect_advance_into(i, "c");
Packit Service 20376f
	expect_advance_into(i, "e");
Packit Service 20376f
	expect_advance_into(i, "g");
Packit Service 20376f
	expect_advance_into(i, "i");
Packit Service 20376f
	expect_advance_into(i, "item0");
Packit Service 20376f
	expect_advance_into(i, "item1/");
Packit Service 20376f
	expect_advance_into(i, "item1/item0");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item0");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item1");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item2");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item3");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item4");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item5");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item6");
Packit Service 20376f
	expect_advance_into(i, "item1/item1/item7");
Packit Service 20376f
	expect_advance_into(i, "item1/item2");
Packit Service 20376f
	expect_advance_over(i, "item1/item3/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item1/item4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item1/item5/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item1/item6", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item1/item7/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_into(i, "item2");
Packit Service 20376f
	expect_advance_over(i, "item3/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item5/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item6", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "item7/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_into(i, "k/");
Packit Service 20376f
	expect_advance_into(i, "k/1");
Packit Service 20376f
	expect_advance_into(i, "k/B");
Packit Service 20376f
	expect_advance_into(i, "k/D");
Packit Service 20376f
	expect_advance_into(i, "k/a");
Packit Service 20376f
	expect_advance_into(i, "k/c");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void add_conflict(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const char *ancestor_path,
Packit Service 20376f
	const char *our_path,
Packit Service 20376f
	const char *their_path)
Packit Service 20376f
{
Packit Service 20376f
	git_index_entry ancestor = {{0}}, ours = {{0}}, theirs = {{0}};
Packit Service 20376f
Packit Service 20376f
	ancestor.path = ancestor_path;
Packit Service 20376f
	ancestor.mode = GIT_FILEMODE_BLOB;
Packit Service 20376f
	git_oid_fromstr(&ancestor.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
Packit Service 20376f
	GIT_IDXENTRY_STAGE_SET(&ancestor, 1);
Packit Service 20376f
Packit Service 20376f
	ours.path = our_path;
Packit Service 20376f
	ours.mode = GIT_FILEMODE_BLOB;
Packit Service 20376f
	git_oid_fromstr(&ours.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
Packit Service 20376f
	GIT_IDXENTRY_STAGE_SET(&ours, 2);
Packit Service 20376f
Packit Service 20376f
	theirs.path = their_path;
Packit Service 20376f
	theirs.mode = GIT_FILEMODE_BLOB;
Packit Service 20376f
	git_oid_fromstr(&theirs.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
Packit Service 20376f
	GIT_IDXENTRY_STAGE_SET(&theirs, 3);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_iterator_index__include_conflicts(void)
Packit Service 20376f
{
Packit Service 20376f
	git_iterator *i;
Packit Service 20376f
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
Packit Service 20376f
		GIT_ITERATOR_DONT_AUTOEXPAND;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("icase");
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	add_conflict(index, "CONFLICT1", "CONFLICT1" ,"CONFLICT1");
Packit Service 20376f
	add_conflict(index, "ZZZ-CONFLICT2.ancestor", "ZZZ-CONFLICT2.ours", "ZZZ-CONFLICT2.theirs");
Packit Service 20376f
	add_conflict(index, "ancestor.conflict3", "ours.conflict3", "theirs.conflict3");
Packit Service 20376f
	add_conflict(index, "zzz-conflict4", "zzz-conflict4", "zzz-conflict4");
Packit Service 20376f
Packit Service 20376f
	/* Iterate the index, ensuring that conflicts are not included */
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
Packit Service 20376f
	expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	/* Try again, returning conflicts */
Packit Service 20376f
	i_opts.flags |= GIT_ITERATOR_INCLUDE_CONFLICTS;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
Packit Service 20376f
Packit Service 20376f
	expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "ZZZ-CONFLICT2.ancestor", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "ZZZ-CONFLICT2.ours", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "ZZZ-CONFLICT2.theirs", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "ancestor.conflict3", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "ours.conflict3", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "theirs.conflict3", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
	expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
Packit Service 20376f
	git_iterator_free(i);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}