|
| 1 | +#include "clar_libgit2.h" |
| 2 | + |
| 3 | +#include "repository.h" |
| 4 | +#include "buffer.h" |
| 5 | +#include "submodule.h" |
| 6 | + |
| 7 | +static const char *repo_name = "win32-forbidden"; |
| 8 | +static git_repository *repo; |
| 9 | + |
| 10 | +void test_win32_forbidden__initialize(void) |
| 11 | +{ |
| 12 | + repo = cl_git_sandbox_init(repo_name); |
| 13 | +} |
| 14 | + |
| 15 | +void test_win32_forbidden__cleanup(void) |
| 16 | +{ |
| 17 | + cl_git_sandbox_cleanup(); |
| 18 | +} |
| 19 | + |
| 20 | +void test_win32_forbidden__can_open_index(void) |
| 21 | +{ |
| 22 | + git_index *index; |
| 23 | + cl_git_pass(git_repository_index(&index, repo)); |
| 24 | + cl_assert_equal_i(7, git_index_entrycount(index)); |
| 25 | + |
| 26 | + /* ensure we can even write the unmodified index */ |
| 27 | + cl_git_pass(git_index_write(index)); |
| 28 | + |
| 29 | + git_index_free(index); |
| 30 | +} |
| 31 | + |
| 32 | +void test_win32_forbidden__can_add_forbidden_filename_with_entry(void) |
| 33 | +{ |
| 34 | + git_index *index; |
| 35 | + git_index_entry entry = {{0}}; |
| 36 | + |
| 37 | + cl_git_pass(git_repository_index(&index, repo)); |
| 38 | + |
| 39 | + entry.path = "aux"; |
| 40 | + entry.mode = GIT_FILEMODE_BLOB; |
| 41 | + git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37"); |
| 42 | + |
| 43 | + cl_git_pass(git_index_add(index, &entry)); |
| 44 | + |
| 45 | + git_index_free(index); |
| 46 | +} |
| 47 | + |
| 48 | +void test_win32_forbidden__cannot_add_dot_git_even_with_entry(void) |
| 49 | +{ |
| 50 | + git_index *index; |
| 51 | + git_index_entry entry = {{0}}; |
| 52 | + |
| 53 | + cl_git_pass(git_repository_index(&index, repo)); |
| 54 | + |
| 55 | + entry.path = "foo/.git"; |
| 56 | + entry.mode = GIT_FILEMODE_BLOB; |
| 57 | + git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37"); |
| 58 | + |
| 59 | + cl_git_fail(git_index_add(index, &entry)); |
| 60 | + |
| 61 | + git_index_free(index); |
| 62 | +} |
| 63 | + |
| 64 | +void test_win32_forbidden__cannot_add_forbidden_filename_from_filesystem(void) |
| 65 | +{ |
| 66 | + git_index *index; |
| 67 | + |
| 68 | + /* since our function calls are very low-level, we can create `aux.`, |
| 69 | + * but we should not be able to add it to the index |
| 70 | + */ |
| 71 | + cl_git_pass(git_repository_index(&index, repo)); |
| 72 | + cl_git_write2file("win32-forbidden/aux.", "foo\n", 4, O_RDWR | O_CREAT, 0666); |
| 73 | + |
| 74 | +#ifdef GIT_WIN32 |
| 75 | + cl_git_fail(git_index_add_bypath(index, "aux.")); |
| 76 | +#else |
| 77 | + cl_git_pass(git_index_add_bypath(index, "aux.")); |
| 78 | +#endif |
| 79 | + |
| 80 | + cl_must_pass(p_unlink("win32-forbidden/aux.")); |
| 81 | + git_index_free(index); |
| 82 | +} |
| 83 | + |
| 84 | +static int dummy_submodule_cb( |
| 85 | + git_submodule *sm, const char *name, void *payload) |
| 86 | +{ |
| 87 | + GIT_UNUSED(sm); |
| 88 | + GIT_UNUSED(name); |
| 89 | + GIT_UNUSED(payload); |
| 90 | + return 0; |
| 91 | +} |
| 92 | + |
| 93 | +void test_win32_forbidden__can_diff_tree_to_index(void) |
| 94 | +{ |
| 95 | + git_diff *diff; |
| 96 | + git_tree *tree; |
| 97 | + |
| 98 | + cl_git_pass(git_repository_head_tree(&tree, repo)); |
| 99 | + cl_git_pass(git_diff_tree_to_index(&diff, repo, tree, NULL, NULL)); |
| 100 | + cl_assert_equal_i(0, git_diff_num_deltas(diff)); |
| 101 | + git_diff_free(diff); |
| 102 | + git_tree_free(tree); |
| 103 | +} |
| 104 | + |
| 105 | +void test_win32_forbidden__can_diff_tree_to_tree(void) |
| 106 | +{ |
| 107 | + git_diff *diff; |
| 108 | + git_tree *tree; |
| 109 | + |
| 110 | + cl_git_pass(git_repository_head_tree(&tree, repo)); |
| 111 | + cl_git_pass(git_diff_tree_to_tree(&diff, repo, tree, tree, NULL)); |
| 112 | + cl_assert_equal_i(0, git_diff_num_deltas(diff)); |
| 113 | + git_diff_free(diff); |
| 114 | + git_tree_free(tree); |
| 115 | +} |
| 116 | + |
| 117 | +void test_win32_forbidden__can_diff_index_to_workdir(void) |
| 118 | +{ |
| 119 | + git_index *index; |
| 120 | + git_diff *diff; |
| 121 | + const git_diff_delta *delta; |
| 122 | + git_tree *tree; |
| 123 | + size_t i; |
| 124 | + |
| 125 | + cl_git_pass(git_repository_index(&index, repo)); |
| 126 | + cl_git_pass(git_repository_head_tree(&tree, repo)); |
| 127 | + cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL)); |
| 128 | + |
| 129 | + for (i = 0; i < git_diff_num_deltas(diff); i++) { |
| 130 | + delta = git_diff_get_delta(diff, i); |
| 131 | + cl_assert_equal_i(GIT_DELTA_DELETED, delta->status); |
| 132 | + } |
| 133 | + |
| 134 | + git_diff_free(diff); |
| 135 | + git_tree_free(tree); |
| 136 | + git_index_free(index); |
| 137 | +} |
| 138 | + |
| 139 | +void test_win32_forbidden__checking_out_forbidden_index_fails(void) |
| 140 | +{ |
| 141 | +#ifdef GIT_WIN32 |
| 142 | + git_index *index; |
| 143 | + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; |
| 144 | + git_diff *diff; |
| 145 | + const git_diff_delta *delta; |
| 146 | + git_tree *tree; |
| 147 | + size_t num_deltas, i; |
| 148 | + |
| 149 | + opts.checkout_strategy = GIT_CHECKOUT_FORCE; |
| 150 | + |
| 151 | + cl_git_pass(git_repository_index(&index, repo)); |
| 152 | + cl_git_fail(git_checkout_index(repo, index, &opts)); |
| 153 | + |
| 154 | + cl_git_pass(git_repository_head_tree(&tree, repo)); |
| 155 | + cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL)); |
| 156 | + |
| 157 | + num_deltas = git_diff_num_deltas(diff); |
| 158 | + |
| 159 | + cl_assert(num_deltas > 0); |
| 160 | + |
| 161 | + for (i = 0; i < num_deltas; i++) { |
| 162 | + delta = git_diff_get_delta(diff, i); |
| 163 | + cl_assert_equal_i(GIT_DELTA_DELETED, delta->status); |
| 164 | + } |
| 165 | + |
| 166 | + git_diff_free(diff); |
| 167 | + git_tree_free(tree); |
| 168 | + git_index_free(index); |
| 169 | +#endif |
| 170 | +} |
| 171 | + |
| 172 | +void test_win32_forbidden__can_query_submodules(void) |
| 173 | +{ |
| 174 | + cl_git_pass(git_submodule_foreach(repo, dummy_submodule_cb, NULL)); |
| 175 | +} |
| 176 | + |
| 177 | +void test_win32_forbidden__can_blame_file(void) |
| 178 | +{ |
| 179 | + git_blame *blame; |
| 180 | + |
| 181 | + cl_git_pass(git_blame_file(&blame, repo, "aux", NULL)); |
| 182 | + git_blame_free(blame); |
| 183 | +} |
0 commit comments