diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-09-29 22:49:16 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-09-30 16:06:09 +0300 |
commit | 21515f228b739a3ecd2237bafbba50e8d219d8dd (patch) | |
tree | edfbd52eee693f03e4e5248b05c74d45e48fa02d /tests/index | |
parent | 10df661b8cd2a7e4751f8344633825dfc88be169 (diff) |
index: also try conflict mode when inserting
When we do not trust the on-disk mode, we use the mode of an existing
index entry. This allows us to preserve executable bits on platforms
that do not honor them on the filesystem.
If there is no stage 0 index entry, also look at conflicts to attempt
to answer this question: prefer the data from the 'ours' side, then
the 'theirs' side before falling back to the common ancestor.
Diffstat (limited to 'tests/index')
-rw-r--r-- | tests/index/bypath.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/index/bypath.c b/tests/index/bypath.c index d26273f76..0c10cfe4c 100644 --- a/tests/index/bypath.c +++ b/tests/index/bypath.c @@ -242,7 +242,8 @@ void test_index_bypath__add_honors_existing_case_4(void) void test_index_bypath__add_honors_mode(void) { - git_index_entry *entry, new_entry; + const git_index_entry *entry; + git_index_entry new_entry; cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); @@ -263,3 +264,67 @@ void test_index_bypath__add_honors_mode(void) cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); cl_assert_equal_i(GIT_FILEMODE_BLOB_EXECUTABLE, entry->mode); } + +void test_index_bypath__add_honors_conflict_mode(void) +{ + const git_index_entry *entry; + git_index_entry new_entry; + int stage = 0; + + cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); + + memcpy(&new_entry, entry, sizeof(git_index_entry)); + new_entry.path = "README.txt"; + new_entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE; + + cl_must_pass(p_chmod("submod2/README.txt", GIT_FILEMODE_BLOB_EXECUTABLE)); + + cl_git_pass(git_index_remove_bypath(g_idx, "README.txt")); + + for (stage = 1; stage <= 3; stage++) { + new_entry.flags = stage << GIT_IDXENTRY_STAGESHIFT; + cl_git_pass(git_index_add(g_idx, &new_entry)); + } + + cl_git_pass(git_index_write(g_idx)); + + cl_git_rewritefile("submod2/README.txt", "Modified but still executable"); + + cl_git_pass(git_index_add_bypath(g_idx, "README.txt")); + cl_git_pass(git_index_write(g_idx)); + + cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); + cl_assert_equal_i(GIT_FILEMODE_BLOB_EXECUTABLE, entry->mode); +} + +void test_index_bypath__add_honors_conflict_case(void) +{ + const git_index_entry *entry; + git_index_entry new_entry; + int stage = 0; + + cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); + + memcpy(&new_entry, entry, sizeof(git_index_entry)); + new_entry.path = "README.txt"; + new_entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE; + + cl_must_pass(p_chmod("submod2/README.txt", GIT_FILEMODE_BLOB_EXECUTABLE)); + + cl_git_pass(git_index_remove_bypath(g_idx, "README.txt")); + + for (stage = 1; stage <= 3; stage++) { + new_entry.flags = stage << GIT_IDXENTRY_STAGESHIFT; + cl_git_pass(git_index_add(g_idx, &new_entry)); + } + + cl_git_pass(git_index_write(g_idx)); + + cl_git_rewritefile("submod2/README.txt", "Modified but still executable"); + + cl_git_pass(git_index_add_bypath(g_idx, "README.txt")); + cl_git_pass(git_index_write(g_idx)); + + cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL); + cl_assert_equal_i(GIT_FILEMODE_BLOB_EXECUTABLE, entry->mode); +} |