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