]> git.proxmox.com Git - libgit2.git/commitdiff
checkout: Deploy EMERGECONFLICT usage
authornulltoken <emeric.fermas@gmail.com>
Thu, 10 Jan 2013 22:27:13 +0000 (23:27 +0100)
committernulltoken <emeric.fermas@gmail.com>
Fri, 11 Jan 2013 18:30:58 +0000 (19:30 +0100)
src/checkout.c
tests-clar/checkout/tree.c

index 4d6f99463a3a9c34a956bfba3113e4856a6584c9..cca66c34fce3a97e8daac0dea15665deaf25af68 100644 (file)
@@ -616,7 +616,7 @@ static int checkout_get_actions(
        {
                giterr_set(GITERR_CHECKOUT, "%d conflicts prevent checkout",
                        (int)counts[CHECKOUT_ACTION__CONFLICT]);
-               error = -1;
+               error = GIT_EMERGECONFLICT;
                goto fail;
        }
 
index 2fd5667d4f899020e4d7669ccafd518cba8a8c0a..80e26a15a0d06793a73b1bddaf62c59d42f8f68a 100644 (file)
@@ -356,3 +356,89 @@ void test_checkout_tree__can_disable_pattern_match(void)
 
        cl_assert(git_path_isfile("testrepo/branch_file.txt"));
 }
+
+void assert_conflict(
+       const char *entry_path,
+       const char *new_content,
+       const char *parent_sha,
+       const char *commit_sha)
+{
+       git_index *index;
+       git_object *hack_tree;
+       git_reference *branch, *head;
+       git_buf file_path = GIT_BUF_INIT; 
+       git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+       cl_git_pass(git_repository_index(&index, g_repo));
+
+       /* Create a branch pointing at the parent */
+       cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
+       cl_git_pass(git_branch_create(&branch, g_repo,
+               "potential_conflict", (git_commit *)g_object, 0));
+
+       /* Make HEAD point to this branch */
+       cl_git_pass(git_reference_symbolic_create(
+               &head, g_repo, "HEAD", git_reference_name(branch), 1));
+
+       /* Checkout the parent */
+       opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+       cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+       /* Hack-ishy workaound to ensure *all* the index entries
+        * match the content of the tree
+        */
+       cl_git_pass(git_object_peel(&hack_tree, g_object, GIT_OBJ_TREE));
+       cl_git_pass(git_index_read_tree(index, (git_tree *)hack_tree));
+       git_object_free(hack_tree);
+       git_object_free(g_object);
+       g_object = NULL;
+
+       /* Create a conflicting file */
+       cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
+       cl_git_mkfile(git_buf_cstr(&file_path), new_content);
+       git_buf_free(&file_path);
+
+       /* Trying to checkout the original commit */
+       cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));
+
+       opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+       cl_assert_equal_i(
+               GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
+
+       /* Stage the conflicting change */
+       cl_git_pass(git_index_add_from_workdir(index, entry_path));
+       cl_git_pass(git_index_write(index));
+
+       cl_assert_equal_i(
+               GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
+}
+
+void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT(void)
+{
+       /*
+        * 099faba adds a symlink named 'link_to_new.txt'
+        * a65fedf is the parent of 099faba
+        */
+
+       assert_conflict("link_to_new.txt", "old.txt", "a65fedf", "099faba");
+}
+
+void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT_2(void)
+{
+       /*
+        * cf80f8d adds a directory named 'a/'
+        * a4a7dce is the parent of cf80f8d
+        */
+
+       assert_conflict("a", "hello\n", "a4a7dce", "cf80f8d");
+}
+
+void test_checkout_tree__checking_out_a_conflicting_content_change_returns_EMERGECONFLICT(void)
+{
+       /*
+        * c47800c adds a symlink named 'branch_file.txt'
+        * 5b5b025 is the parent of 763d71a
+        */
+
+       assert_conflict("branch_file.txt", "hello\n", "5b5b025", "c47800c");
+}