diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-04-23 17:54:08 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-04-23 17:54:08 +0300 |
commit | 27fa7477b008bff27c5aaecb1b2b908540a5798a (patch) | |
tree | 2e99d688a25f8c11db89323b3f2174495019e848 /tests | |
parent | f564017d964e97c067baf98d2a332873bb641ffc (diff) | |
parent | d3282680ed3c2311aad0f3b9bd256255bbc09ce2 (diff) |
Merge pull request #3032 from jfultz/index-file-modes
Fix git_checkout_tree() to do index filemodes correctly on Windows.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/checkout/tree.c | 29 | ||||
-rw-r--r-- | tests/index/filemodes.c | 79 |
2 files changed, 106 insertions, 2 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index 7d4c784a1..3973d9320 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -925,18 +925,43 @@ void test_checkout_tree__filemode_preserved_in_index(void) git_index *index; const git_index_entry *entry; + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + cl_git_pass(git_repository_index(&index, g_repo)); + /* test a freshly added executable */ cl_git_pass(git_oid_fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); - opts.checkout_strategy = GIT_CHECKOUT_FORCE; - cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); cl_assert(entry = git_index_get_bypath(index, "executable.txt", 0)); cl_assert_equal_i(0100755, entry->mode); git_commit_free(commit); + + + /* Now start with a commit which has a text file */ + cl_git_pass(git_oid_fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + cl_assert(entry = git_index_get_bypath(index, "a/b.txt", 0)); + cl_assert_equal_i(0100644, entry->mode); + + git_commit_free(commit); + + + /* And then check out to a commit which converts the text file to an executable */ + cl_git_pass(git_oid_fromstr(&executable_oid, "144344043ba4d4a405da03de3844aa829ae8be0e")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + cl_assert(entry = git_index_get_bypath(index, "a/b.txt", 0)); + cl_assert_equal_i(0100755, entry->mode); + + git_commit_free(commit); + + git_index_free(index); } diff --git a/tests/index/filemodes.c b/tests/index/filemodes.c index 58d7935a0..b3907996b 100644 --- a/tests/index/filemodes.c +++ b/tests/index/filemodes.c @@ -153,6 +153,85 @@ void test_index_filemodes__trusted(void) git_index_free(index); } +#define add_entry_and_check_mode(I,FF,X) add_entry_and_check_mode_(I,FF,X,__FILE__,__LINE__) + +static void add_entry_and_check_mode_( + git_index *index, bool from_file, git_filemode_t mode, + const char *file, int line) +{ + size_t pos; + const git_index_entry* entry; + git_index_entry new_entry; + + /* If old_filename exists, we copy that to the new file, and test + * git_index_add(), otherwise create a new entry testing git_index_add_frombuffer + */ + if (from_file) + { + clar__assert(!git_index_find(&pos, index, "exec_off"), + file, line, "Cannot find original index entry", NULL, 1); + + entry = git_index_get_byindex(index, pos); + + memcpy(&new_entry, entry, sizeof(new_entry)); + } + else + memset(&new_entry, 0x0, sizeof(git_index_entry)); + + new_entry.path = "filemodes/explicit_test"; + new_entry.mode = mode; + + if (from_file) + { + clar__assert(!git_index_add(index, &new_entry), + file, line, "Cannot add index entry", NULL, 1); + } + else + { + const char *content = "hey there\n"; + clar__assert(!git_index_add_frombuffer(index, &new_entry, content, strlen(content)), + file, line, "Cannot add index entry from buffer", NULL, 1); + } + + clar__assert(!git_index_find(&pos, index, "filemodes/explicit_test"), + file, line, "Cannot find new index entry", NULL, 1); + + entry = git_index_get_byindex(index, pos); + + clar__assert_equal(file, line, "Expected mode does not match index", + 1, "%07o", (unsigned int)entry->mode, (unsigned int)mode); +} + +void test_index_filemodes__explicit(void) +{ + git_index *index; + + /* These tests should run and work everywhere, as the filemode is + * given explicitly to git_index_add or git_index_add_frombuffer + */ + cl_repo_set_bool(g_repo, "core.filemode", false); + + cl_git_pass(git_repository_index(&index, g_repo)); + + /* Each of these tests keeps overwriting the same file in the index. */ + /* 1 - add new 0644 entry */ + add_entry_and_check_mode(index, true, GIT_FILEMODE_BLOB); + + /* 2 - add 0755 entry over existing 0644 */ + add_entry_and_check_mode(index, true, GIT_FILEMODE_BLOB_EXECUTABLE); + + /* 3 - add 0644 entry over existing 0755 */ + add_entry_and_check_mode(index, true, GIT_FILEMODE_BLOB); + + /* 4 - add 0755 buffer entry over existing 0644 */ + add_entry_and_check_mode(index, false, GIT_FILEMODE_BLOB_EXECUTABLE); + + /* 5 - add 0644 buffer entry over existing 0755 */ + add_entry_and_check_mode(index, false, GIT_FILEMODE_BLOB); + + git_index_free(index); +} + void test_index_filemodes__invalid(void) { git_index *index; |