]> git.proxmox.com Git - libgit2.git/blobdiff - tests/index/names.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / index / names.c
index 52922e9f126c6d4fbaced98a093a55ae4b54ca87..369318b031ab99852ef640f76aa94d0b8aa150ba 100644 (file)
@@ -10,7 +10,7 @@ static git_index *repo_index;
 #define TEST_REPO_PATH "mergedrepo"
 #define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
 
-// Fixture setup and teardown
+/* Fixture setup and teardown */
 void test_index_names__initialize(void)
 {
        repo = cl_git_sandbox_init("mergedrepo");
@@ -25,10 +25,47 @@ void test_index_names__cleanup(void)
        cl_git_sandbox_cleanup();
 }
 
+static void index_add_conflicts(void)
+{
+       git_index_entry entry = {{0}};
+       const char *paths[][3] = {
+               { "ancestor", "ours", "theirs" },
+               { "ancestor2", "ours2", "theirs2" },
+               { "ancestor3", "ours3", "theirs3" } };
+       const char **conflict;
+       size_t i;
+
+       for (i = 0; i < ARRAY_SIZE(paths); i++) {
+               conflict = paths[i];
+
+               /* ancestor */
+               entry.path = conflict[0];
+               entry.mode = GIT_FILEMODE_BLOB;
+               GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_ANCESTOR);
+               git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+               cl_git_pass(git_index_add(repo_index, &entry));
+
+               /* ours */
+               entry.path = conflict[1];
+               entry.mode = GIT_FILEMODE_BLOB;
+               GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_OURS);
+               git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+               cl_git_pass(git_index_add(repo_index, &entry));
+
+               /* theirs */
+               entry.path = conflict[2];
+               entry.mode = GIT_FILEMODE_BLOB;
+               GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_THEIRS);
+               git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+               cl_git_pass(git_index_add(repo_index, &entry));
+       }
+}
+
 void test_index_names__add(void)
 {
        const git_index_name_entry *conflict_name;
 
+       index_add_conflicts();
        cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
        cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
        cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));
@@ -49,6 +86,8 @@ void test_index_names__add(void)
        cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
        cl_assert(conflict_name->ours == NULL);
        cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
+
+       cl_git_pass(git_index_write(repo_index));
 }
 
 void test_index_names__roundtrip(void)
@@ -89,7 +128,7 @@ void test_index_names__cleaned_on_reset_hard(void)
        cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
 
        test_index_names__add();
-       cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
        cl_assert(git_index_name_entrycount(repo_index) == 0);
 
        git_object_free(target);
@@ -102,7 +141,7 @@ void test_index_names__cleaned_on_reset_mixed(void)
        cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
 
        test_index_names__add();
-       cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL));
+       cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
        cl_assert(git_index_name_entrycount(repo_index) == 0);
 
        git_object_free(target);
@@ -114,12 +153,12 @@ void test_index_names__cleaned_on_checkout_tree(void)
        git_object *obj;
        git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-       opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+       opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
 
        test_index_names__add();
-       git_reference_name_to_id(&oid, repo, "refs/heads/master");
-       git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY);
-       git_checkout_tree(repo, obj, &opts);
+       cl_git_pass(git_reference_name_to_id(&oid, repo, "refs/heads/master"));
+       cl_git_pass(git_object_lookup(&obj, repo, &oid, GIT_OBJECT_ANY));
+       cl_git_pass(git_checkout_tree(repo, obj, &opts));
        cl_assert_equal_sz(0, git_index_name_entrycount(repo_index));
 
        git_object_free(obj);
@@ -129,10 +168,10 @@ void test_index_names__cleaned_on_checkout_head(void)
 {
        git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-       opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+       opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
 
        test_index_names__add();
-       git_checkout_head(repo, &opts);
+       cl_git_pass(git_checkout_head(repo, &opts));
        cl_assert_equal_sz(0, git_index_name_entrycount(repo_index));
 }
 
@@ -140,9 +179,9 @@ void test_index_names__retained_on_checkout_index(void)
 {
        git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-       opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+       opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_UPDATE_ONLY;
 
        test_index_names__add();
-       git_checkout_index(repo, repo_index, &opts);
+       cl_git_pass(git_checkout_index(repo, repo_index, &opts));
        cl_assert(git_index_name_entrycount(repo_index) > 0);
 }