Commit 4f7897ab by Edward Thomson

Prevent checkout_tree when conflicts exist, clear NAME on checkout tree

Prevent checkout tree when unresolved changes exist (unless FORCE flag
is specified).  Clear NAME table when checking out, to avoid
checkout_conflicts from attempting to manipulate it.  Ensure that NAME
is also cleared at reset.
parent 629b661c
......@@ -696,3 +696,47 @@ void test_checkout_tree__extremely_long_file_name(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_assert(!git_path_exists(path));
}
static void create_conflict(void)
{
git_index *index;
git_index_entry entry;
cl_git_pass(git_repository_index(&index, g_repo));
memset(&entry, 0x0, sizeof(git_index_entry));
entry.mode = 0100644;
entry.flags = 1 << GIT_IDXENTRY_STAGESHIFT;
git_oid_fromstr(&entry.oid, "d427e0b2e138501a3d15cc376077a3631e15bd46");
entry.path = "conflicts.txt";
cl_git_pass(git_index_add(index, &entry));
entry.flags = 2 << GIT_IDXENTRY_STAGESHIFT;
git_oid_fromstr(&entry.oid, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
cl_git_pass(git_index_add(index, &entry));
entry.flags = 3 << GIT_IDXENTRY_STAGESHIFT;
git_oid_fromstr(&entry.oid, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
cl_git_pass(git_index_add(index, &entry));
git_index_write(index);
git_index_free(index);
}
void test_checkout_tree__fails_when_conflicts_exist_in_index(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_oid oid;
git_object *obj = NULL;
opts.checkout_strategy = GIT_CHECKOUT_SAFE;
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD"));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
create_conflict();
cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
git_object_free(obj);
}
......@@ -80,5 +80,69 @@ void test_index_names__roundtrip(void)
cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
cl_assert(conflict_name->ours == NULL);
cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
}
void test_index_names__cleaned_on_reset_hard(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
}
void test_index_names__cleaned_on_reset_mixed(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
}
void test_index_names__cleaned_on_checkout_tree(void)
{
git_oid oid;
git_object *obj;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE | 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_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(obj);
}
void test_index_names__cleaned_on_checkout_head(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
test_index_names__add();
git_checkout_head(repo, &opts);
cl_assert(git_index_name_entrycount(repo_index) == 0);
}
void test_index_names__retained_on_checkout_index(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
test_index_names__add();
git_checkout_index(repo, repo_index, &opts);
cl_assert(git_index_name_entrycount(repo_index) > 0);
}
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