Beispiel #1
0
void test_index_reuc__remove(void)
{
	git_oid oid;
	const git_index_reuc_entry *reuc;

	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	cl_git_pass(git_index_reuc_remove(repo_index, 0));
	cl_git_fail(git_index_reuc_remove(repo_index, 1));
	
	cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));

	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));

	cl_assert(strcmp(reuc->path, "two.txt") == 0);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
	git_oid_fromstr(&oid, TWO_OUR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
	git_oid_fromstr(&oid, TWO_THEIR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
}
Beispiel #2
0
void test_index_reuc__ignore_case(void)
{
	const git_index_reuc_entry *reuc;
	git_oid oid;
	int index_caps;

	index_caps = git_index_caps(repo_index);

	index_caps &= ~GIT_INDEXCAP_IGNORE_CASE;
	cl_git_pass(git_index_set_caps(repo_index, index_caps));

	cl_assert(!git_index_reuc_get_bypath(repo_index, "TWO.txt"));

	index_caps |= GIT_INDEXCAP_IGNORE_CASE;
	cl_git_pass(git_index_set_caps(repo_index, index_caps));

	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "TWO.txt"));

	cl_assert(strcmp(reuc->path, "two.txt") == 0);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
	git_oid_fromstr(&oid, TWO_OUR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
	git_oid_fromstr(&oid, TWO_THEIR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
}
Beispiel #3
0
void test_index_reuc__read_bypath(void)
{
	const git_index_reuc_entry *reuc;
	git_oid oid;

	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "two.txt"));

	cl_assert(strcmp(reuc->path, "two.txt") == 0);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
	git_oid_fromstr(&oid, TWO_OUR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
	git_oid_fromstr(&oid, TWO_THEIR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);

	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "one.txt"));

	cl_assert(strcmp(reuc->path, "one.txt") == 0);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
	git_oid_fromstr(&oid, ONE_OUR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
	git_oid_fromstr(&oid, ONE_THEIR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
}
Beispiel #4
0
void test_index_reuc__read_byindex(void)
{
	const git_index_reuc_entry *reuc;
	git_oid oid;

	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));

	cl_assert_equal_s("one.txt", reuc->path);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
	cl_assert_equal_oid(&reuc->oid[0], &oid);
	git_oid_fromstr(&oid, ONE_OUR_OID);
	cl_assert_equal_oid(&reuc->oid[1], &oid);
	git_oid_fromstr(&oid, ONE_THEIR_OID);
	cl_assert_equal_oid(&reuc->oid[2], &oid);

	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));

	cl_assert_equal_s("two.txt", reuc->path);
	cl_assert(reuc->mode[0] == 0100644);
	cl_assert(reuc->mode[1] == 0100644);
	cl_assert(reuc->mode[2] == 0100644);
	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
	cl_assert_equal_oid(&reuc->oid[0], &oid);
	git_oid_fromstr(&oid, TWO_OUR_OID);
	cl_assert_equal_oid(&reuc->oid[1], &oid);
	git_oid_fromstr(&oid, TWO_THEIR_OID);
	cl_assert_equal_oid(&reuc->oid[2], &oid);
}
Beispiel #5
0
/* 5ALT: ancest:*, head:head, remote:head = result:head */
void test_merge_workdir_trivial__5alt_2(void)
{
	const git_index_entry *entry;

	cl_git_pass(merge_trivial("trivial-5alt-2", "trivial-5alt-2-branch", 0));

	cl_assert(entry = git_index_get_bypath(repo_index, "modified-to-same.txt", 0));
	cl_assert(git_index_reuc_entrycount(repo_index) == 0);
	cl_assert(merge_trivial_conflict_entrycount() == 0);
}
Beispiel #6
0
/* 3ALT: ancest:(empty)+, head:head, remote:*empty* = result:head */
void test_merge_workdir_trivial__3alt(void)
{
	const git_index_entry *entry;

	cl_git_pass(merge_trivial("trivial-3alt", "trivial-3alt-branch", 0));

	cl_assert(entry = git_index_get_bypath(repo_index, "new-in-3alt.txt", 0));
	cl_assert(git_index_reuc_entrycount(repo_index) == 0);
	cl_assert(merge_trivial_conflict_entrycount() == 0);
}
Beispiel #7
0
/* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */
void test_merge_workdir_trivial__6(void)
{
	const git_index_entry *entry;

	cl_git_pass(merge_trivial("trivial-6", "trivial-6-branch", 0));

	cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 0)) == NULL);
	cl_assert(git_index_reuc_entrycount(repo_index) == 0);

	cl_assert(merge_trivial_conflict_entrycount() == 1);
	cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 1));
}
Beispiel #8
0
/* 4: ancest:(empty)^, head:head, remote:remote = result:no merge */
void test_merge_workdir_trivial__4(void)
{
	const git_index_entry *entry;

	cl_git_pass(merge_trivial("trivial-4", "trivial-4-branch", 0));

	cl_assert((entry = git_index_get_bypath(repo_index, "new-and-different.txt", 0)) == NULL);
	cl_assert(git_index_reuc_entrycount(repo_index) == 0);

	cl_assert(merge_trivial_conflict_entrycount() == 2);
	cl_assert(entry = git_index_get_bypath(repo_index, "new-and-different.txt", 2));
	cl_assert(entry = git_index_get_bypath(repo_index, "new-and-different.txt", 3));
}
Beispiel #9
0
/* 11: ancest:ancest+, head:head, remote:remote = result:no merge */
void test_merge_workdir_trivial__11(void)
{
	const git_index_entry *entry;

	cl_git_pass(merge_trivial("trivial-11", "trivial-11-branch", 0));

	cl_assert((entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 0)) == NULL);
	cl_assert(git_index_reuc_entrycount(repo_index) == 0);

	cl_assert(merge_trivial_conflict_entrycount() == 3);
	cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 1));
	cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 2));
	cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 3));
}
Beispiel #10
0
/* 14: ancest:ancest+, head:ancest, remote:remote = result:remote */
void test_merge_workdir_trivial__14(void)
{
	const git_index_entry *entry;
	git_oid expected_oid;

	cl_git_pass(merge_trivial("trivial-14", "trivial-14-branch", 0));

	cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-14-branch.txt", 0));
	cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9"));
	cl_assert(git_oid_cmp(&entry->oid, &expected_oid) == 0);

	cl_assert(git_index_reuc_entrycount(repo_index) == 0);
	cl_assert(merge_trivial_conflict_entrycount() == 0);
}
Beispiel #11
0
/* 13: ancest:ancest+, head:head, remote:ancest = result:head */
void test_merge_workdir_trivial__13(void)
{
	const git_index_entry *entry;
	git_oid expected_oid;

	cl_git_pass(merge_trivial("trivial-13", "trivial-13-branch", 0));

	cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-13.txt", 0));
	cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b"));
	cl_assert(git_oid_cmp(&entry->oid, &expected_oid) == 0);

	cl_assert(git_index_reuc_entrycount(repo_index) == 0);
	cl_assert(merge_trivial_conflict_entrycount() == 0);
}
int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], size_t expected_len)
{
	size_t i;
	const git_index_reuc_entry *reuc_entry;
	git_oid expected_oid;

	/*
	dump_reuc(index);
	*/

	if (git_index_reuc_entrycount(index) != expected_len)
		return 0;

	for (i = 0; i < expected_len; i++) {
		if ((reuc_entry = git_index_reuc_get_byindex(index, i)) == NULL)
			return 0;

		if (strcmp(reuc_entry->path, expected[i].path) != 0 ||
			reuc_entry->mode[0] != expected[i].ancestor_mode ||
			reuc_entry->mode[1] != expected[i].our_mode ||
			reuc_entry->mode[2] != expected[i].their_mode)
			return 0;

		if (expected[i].ancestor_mode > 0) {
			cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].ancestor_oid_str));

			if (git_oid_cmp(&reuc_entry->oid[0], &expected_oid) != 0)
				return 0;
		}

		if (expected[i].our_mode > 0) {
			cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].our_oid_str));

			if (git_oid_cmp(&reuc_entry->oid[1], &expected_oid) != 0)
				return 0;
		}

		if (expected[i].their_mode > 0) {
			cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].their_oid_str));

			if (git_oid_cmp(&reuc_entry->oid[2], &expected_oid) != 0)
				return 0;
		}
	}

	return 1;
}
void merge__dump_reuc(git_index *index)
{
	size_t i;
	const git_index_reuc_entry *reuc;

	printf ("\nREUC:\n");
	for (i = 0; i < git_index_reuc_entrycount(index); i++) {
		reuc = git_index_reuc_get_byindex(index, i);

		printf("%s ", reuc->path);
		printf("%o ", reuc->mode[0]);
		printf("%s\n", git_oid_allocfmt(&reuc->oid[0]));
		printf("          %o ", reuc->mode[1]);
		printf("          %s\n", git_oid_allocfmt(&reuc->oid[1]));
		printf("          %o ", reuc->mode[2]);
		printf("          %s ", git_oid_allocfmt(&reuc->oid[2]));
		printf("\n");
	}
	printf("\n");
}
Beispiel #14
0
void test_index_reuc__updates_existing(void)
{
	const git_index_reuc_entry *reuc;
	git_oid ancestor_oid, our_oid, their_oid, oid;
	int index_caps;

	git_index_clear(repo_index);

	index_caps = git_index_caps(repo_index);

	index_caps |= GIT_INDEXCAP_IGNORE_CASE;
	cl_git_pass(git_index_set_caps(repo_index, index_caps));

	git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
	git_oid_fromstr(&our_oid, TWO_OUR_OID);
	git_oid_fromstr(&their_oid, TWO_THEIR_OID);

	cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
		0100644, &ancestor_oid,
		0100644, &our_oid,
		0100644, &their_oid));

	cl_git_pass(git_index_reuc_add(repo_index, "TWO.txt",
		0100644, &our_oid,
		0100644, &their_oid,
		0100644, &ancestor_oid));

	cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));

	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));

	cl_assert(strcmp(reuc->path, "TWO.txt") == 0);
	git_oid_fromstr(&oid, TWO_OUR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
	git_oid_fromstr(&oid, TWO_THEIR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
}
Beispiel #15
0
void test_index_reuc__write(void)
{
	git_oid ancestor_oid, our_oid, their_oid;
	const git_index_reuc_entry *reuc;

	git_index_clear(repo_index);

	/* Write out of order to ensure sorting is correct */
	git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
	git_oid_fromstr(&our_oid, TWO_OUR_OID);
	git_oid_fromstr(&their_oid, TWO_THEIR_OID);

	cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
		0100644, &ancestor_oid,
		0100644, &our_oid,
		0100644, &their_oid));

	git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID);
	git_oid_fromstr(&our_oid, ONE_OUR_OID);
	git_oid_fromstr(&their_oid, ONE_THEIR_OID);

	cl_git_pass(git_index_reuc_add(repo_index, "one.txt",
		0100644, &ancestor_oid,
		0100644, &our_oid,
		0100644, &their_oid));

	cl_git_pass(git_index_write(repo_index));

	cl_git_pass(git_index_read(repo_index));
	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	/* ensure sort order was round-tripped correct */
	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
	cl_assert(strcmp(reuc->path, "one.txt") == 0);
	
	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
	cl_assert(strcmp(reuc->path, "two.txt") == 0);
}
Beispiel #16
0
void test_merge_workdir_fastforward__no_fastforward(void)
{
    git_merge_result *result;

    struct merge_index_entry merge_index_entries[] = {
        { 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
        { 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" },
        { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
        { 0100644, "bd9cb4cd0a770cb9adcb5fce212142ef40ea1c35", 0, "changed-in-master.txt" },
        { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" },
        { 0100644, "364bbe4ce80c7bd31e6307dce77d46e3e1759fb3", 0, "new-in-ff.txt" },
        { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
        { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
    };

    cl_assert(result = merge_fastforward_branch(GIT_MERGE_NO_FASTFORWARD));
    cl_assert(!git_merge_result_is_fastforward(result));

    cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
    cl_assert(git_index_reuc_entrycount(repo_index) == 0);

    git_merge_result_free(result);
}