1 #include "clar_libgit2.h"
3 #include "repository.h"
6 static const char *repo_name
= "win32-forbidden";
7 static git_repository
*repo
;
9 void test_win32_forbidden__initialize(void)
11 repo
= cl_git_sandbox_init(repo_name
);
14 void test_win32_forbidden__cleanup(void)
16 cl_git_sandbox_cleanup();
19 void test_win32_forbidden__can_open_index(void)
22 cl_git_pass(git_repository_index(&index
, repo
));
23 cl_assert_equal_i(7, git_index_entrycount(index
));
25 /* ensure we can even write the unmodified index */
26 cl_git_pass(git_index_write(index
));
28 git_index_free(index
);
31 void test_win32_forbidden__can_add_forbidden_filename_with_entry(void)
34 git_index_entry entry
= {{0}};
36 cl_git_pass(git_repository_index(&index
, repo
));
39 entry
.mode
= GIT_FILEMODE_BLOB
;
40 git_oid_fromstr(&entry
.id
, "da623abd956bb2fd8052c708c7ed43f05d192d37");
42 cl_git_pass(git_index_add(index
, &entry
));
44 git_index_free(index
);
47 void test_win32_forbidden__cannot_add_dot_git_even_with_entry(void)
50 git_index_entry entry
= {{0}};
52 cl_git_pass(git_repository_index(&index
, repo
));
54 entry
.path
= "foo/.git";
55 entry
.mode
= GIT_FILEMODE_BLOB
;
56 git_oid_fromstr(&entry
.id
, "da623abd956bb2fd8052c708c7ed43f05d192d37");
58 cl_git_fail(git_index_add(index
, &entry
));
60 git_index_free(index
);
63 void test_win32_forbidden__cannot_add_forbidden_filename_from_filesystem(void)
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
70 cl_git_pass(git_repository_index(&index
, repo
));
71 cl_git_write2file("win32-forbidden/aux.", "foo\n", 4, O_RDWR
| O_CREAT
, 0666);
74 cl_git_fail(git_index_add_bypath(index
, "aux."));
76 cl_git_pass(git_index_add_bypath(index
, "aux."));
79 cl_must_pass(p_unlink("win32-forbidden/aux."));
80 git_index_free(index
);
83 static int dummy_submodule_cb(
84 git_submodule
*sm
, const char *name
, void *payload
)
92 void test_win32_forbidden__can_diff_tree_to_index(void)
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
));
104 void test_win32_forbidden__can_diff_tree_to_tree(void)
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
));
116 void test_win32_forbidden__can_diff_index_to_workdir(void)
120 const git_diff_delta
*delta
;
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
));
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
);
135 git_index_free(index
);
138 void test_win32_forbidden__checking_out_forbidden_index_fails(void)
142 git_checkout_options opts
= GIT_CHECKOUT_OPTIONS_INIT
;
144 const git_diff_delta
*delta
;
146 size_t num_deltas
, i
;
148 opts
.checkout_strategy
= GIT_CHECKOUT_FORCE
;
150 cl_git_pass(git_repository_index(&index
, repo
));
151 cl_git_fail(git_checkout_index(repo
, index
, &opts
));
153 cl_git_pass(git_repository_head_tree(&tree
, repo
));
154 cl_git_pass(git_diff_index_to_workdir(&diff
, repo
, index
, NULL
));
156 num_deltas
= git_diff_num_deltas(diff
);
158 cl_assert(num_deltas
> 0);
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
);
167 git_index_free(index
);
171 void test_win32_forbidden__can_query_submodules(void)
173 cl_git_pass(git_submodule_foreach(repo
, dummy_submodule_cb
, NULL
));
176 void test_win32_forbidden__can_blame_file(void)
180 cl_git_pass(git_blame_file(&blame
, repo
, "aux", NULL
));
181 git_blame_free(blame
);