diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2014-11-06 14:40:21 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2014-11-06 18:49:57 -0500 |
| commit | 9f664347ff74716dc35ff0bd9a1a87606ae29cf0 (patch) | |
| tree | cecd6d3e38e2565d0b828ecafbc7033d6b0c12df /tests | |
| parent | 64dc248577940c7874939bb82b6a557bafe8c388 (diff) | |
| download | libgit2-9f664347ff74716dc35ff0bd9a1a87606ae29cf0.tar.gz | |
checkout_index: remove conflicts when checking out new files
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/checkout/tree.c | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index 0933f64f7..3212d6503 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -882,7 +882,7 @@ void test_checkout_tree__extremely_long_file_name(void) cl_assert(!git_path_exists(path)); } -static void create_conflict(void) +static void create_conflict(const char *path) { git_index *index; git_index_entry entry; @@ -893,7 +893,7 @@ static void create_conflict(void) entry.mode = 0100644; entry.flags = 1 << GIT_IDXENTRY_STAGESHIFT; git_oid_fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); - entry.path = "conflicts.txt"; + entry.path = path; cl_git_pass(git_index_add(index, &entry)); entry.flags = 2 << GIT_IDXENTRY_STAGESHIFT; @@ -919,7 +919,7 @@ void test_checkout_tree__fails_when_conflicts_exist_in_index(void) 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(); + create_conflict("conflicts.txt"); cl_git_fail(git_checkout_tree(g_repo, obj, &opts)); @@ -948,3 +948,87 @@ void test_checkout_tree__filemode_preserved_in_index(void) git_commit_free(commit); git_index_free(index); } + +void test_checkout_tree__removes_conflicts(void) +{ + git_oid commit_id; + git_commit *commit; + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + git_index *index; + + cl_git_pass(git_oid_fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); + + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_remove(index, "executable.txt", 0)); + + create_conflict("executable.txt"); + cl_git_mkfile("testrepo/executable.txt", "This is the conflict file.\n"); + + create_conflict("other.txt"); + cl_git_mkfile("testrepo/other.txt", "This is another conflict file.\n"); + + git_index_write(index); + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 1)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 2)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 3)); + + cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 1)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 2)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 3)); + + cl_assert(!git_path_exists("testrepo/other.txt")); + + git_index_free(index); +} + + +void test_checkout_tree__removes_conflicts_only_by_pathscope(void) +{ + git_oid commit_id; + git_commit *commit; + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + git_index *index; + const char *path = "executable.txt"; + + cl_git_pass(git_oid_fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); + + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + opts.paths.count = 1; + opts.paths.strings = (char **)&path; + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_remove(index, "executable.txt", 0)); + + create_conflict("executable.txt"); + cl_git_mkfile("testrepo/executable.txt", "This is the conflict file.\n"); + + create_conflict("other.txt"); + cl_git_mkfile("testrepo/other.txt", "This is another conflict file.\n"); + + git_index_write(index); + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 1)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 2)); + cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 3)); + + cl_assert(git_index_get_bypath(index, "other.txt", 1) != NULL); + cl_assert(git_index_get_bypath(index, "other.txt", 2) != NULL); + cl_assert(git_index_get_bypath(index, "other.txt", 3) != NULL); + + cl_assert(git_path_exists("testrepo/other.txt")); + + git_index_free(index); +} |
