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