diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2014-11-06 18:49:37 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2014-11-06 18:50:10 -0500 |
| commit | 2d24816b4611a7392617855f497f81f385092f34 (patch) | |
| tree | 6c561567e48ecd1db8d9a0899779817bc0e47946 /tests | |
| parent | 9f664347ff74716dc35ff0bd9a1a87606ae29cf0 (diff) | |
| download | libgit2-2d24816b4611a7392617855f497f81f385092f34.tar.gz | |
checkout_index: Remove stage 0 when checking out conflicts
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/checkout/index.c | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/tests/checkout/index.c b/tests/checkout/index.c index 3c01e2411..f94556214 100644 --- a/tests/checkout/index.c +++ b/tests/checkout/index.c @@ -619,17 +619,14 @@ void test_checkout_index__can_get_repo_from_index(void) git_index_free(index); } -static void add_conflict(void) +static void add_conflict(git_index *index, const char *path) { - git_index *index; git_index_entry entry; memset(&entry, 0, sizeof(git_index_entry)); - cl_git_pass(git_repository_index(&index, g_repo)); - entry.mode = 0100644; - entry.path = "conflicting.txt"; + entry.path = path; git_oid_fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); entry.flags = (1 << GIT_IDXENTRY_STAGESHIFT); @@ -642,17 +639,19 @@ static void add_conflict(void) git_oid_fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); entry.flags = (3 << GIT_IDXENTRY_STAGESHIFT); cl_git_pass(git_index_add(index, &entry)); - - cl_git_pass(git_index_write(index)); - git_index_free(index); } void test_checkout_index__writes_conflict_file(void) { + git_index *index; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_buf conflicting_buf = GIT_BUF_INIT; - add_conflict(); + cl_git_pass(git_repository_index(&index, g_repo)); + + add_conflict(index, "conflicting.txt"); + cl_git_pass(git_index_write(index)); + cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); cl_git_pass(git_futils_readbuffer(&conflicting_buf, "testrepo/conflicting.txt")); @@ -663,18 +662,46 @@ void test_checkout_index__writes_conflict_file(void) "this file is changed in branch and master\n" ">>>>>>> theirs\n") == 0); git_buf_free(&conflicting_buf); + + git_index_free(index); +} + +void test_checkout_index__adding_conflict_removes_stage_0(void) +{ + git_index *new_index, *index; + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + + cl_git_pass(git_index_new(&new_index)); + + add_conflict(new_index, "new.txt"); + cl_git_pass(git_checkout_index(g_repo, new_index, &opts)); + + cl_git_pass(git_repository_index(&index, g_repo)); + + cl_assert(git_index_get_bypath(index, "new.txt", 0) == NULL); + cl_assert(git_index_get_bypath(index, "new.txt", 1) != NULL); + cl_assert(git_index_get_bypath(index, "new.txt", 2) != NULL); + cl_assert(git_index_get_bypath(index, "new.txt", 3) != NULL); + + git_index_free(index); + git_index_free(new_index); } void test_checkout_index__conflicts_honor_coreautocrlf(void) { #ifdef GIT_WIN32 + git_index *index; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_buf conflicting_buf = GIT_BUF_INIT; cl_git_pass(p_unlink("./testrepo/.gitattributes")); cl_repo_set_bool(g_repo, "core.autocrlf", true); - add_conflict(); + cl_git_pass(git_repository_index(&index, g_repo)); + + add_conflict(index, "conflicting.txt"); + cl_git_pass(git_index_write(index)); + cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); cl_git_pass(git_futils_readbuffer(&conflicting_buf, "testrepo/conflicting.txt")); @@ -685,5 +712,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void) "this file is changed in branch and master\r\n" ">>>>>>> theirs\r\n") == 0); git_buf_free(&conflicting_buf); + + git_index_free(index); #endif } |
