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(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); cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1)); 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); }
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_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); }
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); }
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"); }
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); }