Commit 4a0ac175 by nulltoken

checkout: Deploy EMERGECONFLICT usage

parent 635c235c
......@@ -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;
}
......
......@@ -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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment