]>
Commit | Line | Data |
---|---|---|
f30fff45 RB |
1 | #include "clar_libgit2.h" |
2 | #include "../status/status_helpers.h" | |
3 | #include "posix.h" | |
22a2d3d5 | 4 | #include "futils.h" |
f30fff45 | 5 | |
0d8265c8 | 6 | static git_repository *g_repo = NULL; |
8b22d862 | 7 | #define TEST_DIR "addall" |
f30fff45 RB |
8 | |
9 | void test_index_addall__initialize(void) | |
10 | { | |
11 | } | |
12 | ||
13 | void test_index_addall__cleanup(void) | |
14 | { | |
666ae188 | 15 | cl_git_sandbox_cleanup(); |
f30fff45 RB |
16 | } |
17 | ||
18 | #define STATUS_INDEX_FLAGS \ | |
19 | (GIT_STATUS_INDEX_NEW | GIT_STATUS_INDEX_MODIFIED | \ | |
20 | GIT_STATUS_INDEX_DELETED | GIT_STATUS_INDEX_RENAMED | \ | |
21 | GIT_STATUS_INDEX_TYPECHANGE) | |
22 | ||
23 | #define STATUS_WT_FLAGS \ | |
24 | (GIT_STATUS_WT_NEW | GIT_STATUS_WT_MODIFIED | \ | |
25 | GIT_STATUS_WT_DELETED | GIT_STATUS_WT_TYPECHANGE | \ | |
26 | GIT_STATUS_WT_RENAMED) | |
27 | ||
28 | typedef struct { | |
29 | size_t index_adds; | |
30 | size_t index_dels; | |
31 | size_t index_mods; | |
32 | size_t wt_adds; | |
33 | size_t wt_dels; | |
34 | size_t wt_mods; | |
35 | size_t ignores; | |
666ae188 | 36 | size_t conflicts; |
f30fff45 RB |
37 | } index_status_counts; |
38 | ||
39 | static int index_status_cb( | |
40 | const char *path, unsigned int status_flags, void *payload) | |
41 | { | |
42 | index_status_counts *vals = payload; | |
43 | ||
44 | /* cb_status__print(path, status_flags, NULL); */ | |
45 | ||
46 | GIT_UNUSED(path); | |
47 | ||
48 | if (status_flags & GIT_STATUS_INDEX_NEW) | |
49 | vals->index_adds++; | |
50 | if (status_flags & GIT_STATUS_INDEX_MODIFIED) | |
51 | vals->index_mods++; | |
52 | if (status_flags & GIT_STATUS_INDEX_DELETED) | |
53 | vals->index_dels++; | |
54 | if (status_flags & GIT_STATUS_INDEX_TYPECHANGE) | |
55 | vals->index_mods++; | |
56 | ||
57 | if (status_flags & GIT_STATUS_WT_NEW) | |
58 | vals->wt_adds++; | |
59 | if (status_flags & GIT_STATUS_WT_MODIFIED) | |
60 | vals->wt_mods++; | |
61 | if (status_flags & GIT_STATUS_WT_DELETED) | |
62 | vals->wt_dels++; | |
63 | if (status_flags & GIT_STATUS_WT_TYPECHANGE) | |
64 | vals->wt_mods++; | |
65 | ||
66 | if (status_flags & GIT_STATUS_IGNORED) | |
67 | vals->ignores++; | |
666ae188 ET |
68 | if (status_flags & GIT_STATUS_CONFLICTED) |
69 | vals->conflicts++; | |
f30fff45 RB |
70 | |
71 | return 0; | |
72 | } | |
73 | ||
4bf630b6 | 74 | static void check_status_at_line( |
f30fff45 RB |
75 | git_repository *repo, |
76 | size_t index_adds, size_t index_dels, size_t index_mods, | |
4bf630b6 | 77 | size_t wt_adds, size_t wt_dels, size_t wt_mods, size_t ignores, |
22a2d3d5 | 78 | size_t conflicts, const char *file, const char *func, int line) |
f30fff45 RB |
79 | { |
80 | index_status_counts vals; | |
81 | ||
82 | memset(&vals, 0, sizeof(vals)); | |
83 | ||
84 | cl_git_pass(git_status_foreach(repo, index_status_cb, &vals)); | |
85 | ||
4bf630b6 | 86 | clar__assert_equal( |
22a2d3d5 | 87 | file,func,line,"wrong index adds", 1, "%"PRIuZ, index_adds, vals.index_adds); |
4bf630b6 | 88 | clar__assert_equal( |
22a2d3d5 | 89 | file,func,line,"wrong index dels", 1, "%"PRIuZ, index_dels, vals.index_dels); |
4bf630b6 | 90 | clar__assert_equal( |
22a2d3d5 | 91 | file,func,line,"wrong index mods", 1, "%"PRIuZ, index_mods, vals.index_mods); |
4bf630b6 | 92 | clar__assert_equal( |
22a2d3d5 | 93 | file,func,line,"wrong workdir adds", 1, "%"PRIuZ, wt_adds, vals.wt_adds); |
4bf630b6 | 94 | clar__assert_equal( |
22a2d3d5 | 95 | file,func,line,"wrong workdir dels", 1, "%"PRIuZ, wt_dels, vals.wt_dels); |
4bf630b6 | 96 | clar__assert_equal( |
22a2d3d5 | 97 | file,func,line,"wrong workdir mods", 1, "%"PRIuZ, wt_mods, vals.wt_mods); |
4bf630b6 | 98 | clar__assert_equal( |
22a2d3d5 | 99 | file,func,line,"wrong ignores", 1, "%"PRIuZ, ignores, vals.ignores); |
666ae188 | 100 | clar__assert_equal( |
22a2d3d5 | 101 | file,func,line,"wrong conflicts", 1, "%"PRIuZ, conflicts, vals.conflicts); |
f30fff45 RB |
102 | } |
103 | ||
666ae188 | 104 | #define check_status(R,IA,ID,IM,WA,WD,WM,IG,C) \ |
22a2d3d5 | 105 | check_status_at_line(R,IA,ID,IM,WA,WD,WM,IG,C,__FILE__,__func__,__LINE__) |
4bf630b6 | 106 | |
f30fff45 RB |
107 | static void check_stat_data(git_index *index, const char *path, bool match) |
108 | { | |
109 | const git_index_entry *entry; | |
110 | struct stat st; | |
111 | ||
112 | cl_must_pass(p_lstat(path, &st)); | |
113 | ||
114 | /* skip repo base dir name */ | |
115 | while (*path != '/') | |
116 | ++path; | |
117 | ++path; | |
118 | ||
119 | entry = git_index_get_bypath(index, path, 0); | |
120 | cl_assert(entry); | |
121 | ||
122 | if (match) { | |
123 | cl_assert(st.st_ctime == entry->ctime.seconds); | |
124 | cl_assert(st.st_mtime == entry->mtime.seconds); | |
125 | cl_assert(st.st_size == entry->file_size); | |
ac3d33df JK |
126 | cl_assert((uint32_t)st.st_uid == entry->uid); |
127 | cl_assert((uint32_t)st.st_gid == entry->gid); | |
c97d407d RB |
128 | cl_assert_equal_i_fmt( |
129 | GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o"); | |
14997dc5 RB |
130 | if (cl_is_chmod_supported()) |
131 | cl_assert_equal_b( | |
132 | GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode)); | |
f30fff45 RB |
133 | } else { |
134 | /* most things will still match */ | |
135 | cl_assert(st.st_size != entry->file_size); | |
136 | /* would check mtime, but with second resolution it won't work :( */ | |
137 | } | |
138 | } | |
139 | ||
8b22d862 RB |
140 | static void addall_create_test_repo(bool check_every_step) |
141 | { | |
666ae188 ET |
142 | g_repo = cl_git_sandbox_init_new(TEST_DIR); |
143 | ||
8b22d862 | 144 | if (check_every_step) |
666ae188 | 145 | check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0); |
8b22d862 RB |
146 | |
147 | cl_git_mkfile(TEST_DIR "/file.foo", "a file"); | |
148 | if (check_every_step) | |
666ae188 | 149 | check_status(g_repo, 0, 0, 0, 1, 0, 0, 0, 0); |
8b22d862 RB |
150 | |
151 | cl_git_mkfile(TEST_DIR "/.gitignore", "*.foo\n"); | |
152 | if (check_every_step) | |
666ae188 | 153 | check_status(g_repo, 0, 0, 0, 1, 0, 0, 1, 0); |
8b22d862 RB |
154 | |
155 | cl_git_mkfile(TEST_DIR "/file.bar", "another file"); | |
156 | if (check_every_step) | |
666ae188 | 157 | check_status(g_repo, 0, 0, 0, 2, 0, 0, 1, 0); |
8b22d862 RB |
158 | } |
159 | ||
f30fff45 RB |
160 | void test_index_addall__repo_lifecycle(void) |
161 | { | |
162 | int error; | |
163 | git_index *index; | |
164 | git_strarray paths = { NULL, 0 }; | |
165 | char *strs[1]; | |
166 | ||
8b22d862 | 167 | addall_create_test_repo(true); |
f30fff45 RB |
168 | |
169 | cl_git_pass(git_repository_index(&index, g_repo)); | |
170 | ||
f30fff45 RB |
171 | strs[0] = "file.*"; |
172 | paths.strings = strs; | |
173 | paths.count = 1; | |
174 | ||
175 | cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); | |
ac3d33df | 176 | cl_git_pass(git_index_write(index)); |
8b22d862 | 177 | check_stat_data(index, TEST_DIR "/file.bar", true); |
666ae188 | 178 | check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0); |
f30fff45 | 179 | |
8b22d862 RB |
180 | cl_git_rewritefile(TEST_DIR "/file.bar", "new content for file"); |
181 | check_stat_data(index, TEST_DIR "/file.bar", false); | |
666ae188 | 182 | check_status(g_repo, 1, 0, 0, 1, 0, 1, 1, 0); |
f30fff45 | 183 | |
8b22d862 RB |
184 | cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one"); |
185 | cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one"); | |
186 | cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one"); | |
666ae188 | 187 | check_status(g_repo, 1, 0, 0, 4, 0, 1, 1, 0); |
f30fff45 RB |
188 | |
189 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
8b22d862 | 190 | check_stat_data(index, TEST_DIR "/file.bar", true); |
666ae188 | 191 | check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0); |
f30fff45 RB |
192 | |
193 | cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); | |
ac3d33df | 194 | cl_git_pass(git_index_write(index)); |
8b22d862 | 195 | check_stat_data(index, TEST_DIR "/file.zzz", true); |
666ae188 | 196 | check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0); |
f30fff45 | 197 | |
155fa234 | 198 | cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "first commit"); |
666ae188 | 199 | check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); |
f30fff45 | 200 | |
2b2dfe80 CMN |
201 | if (cl_repo_get_bool(g_repo, "core.filemode")) { |
202 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
203 | cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0777)); | |
204 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
666ae188 | 205 | check_status(g_repo, 0, 0, 1, 3, 0, 0, 1, 0); |
2b2dfe80 CMN |
206 | |
207 | /* go back to what we had before */ | |
208 | cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0666)); | |
209 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
666ae188 | 210 | check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); |
2b2dfe80 CMN |
211 | } |
212 | ||
213 | ||
f30fff45 RB |
214 | /* attempt to add an ignored file - does nothing */ |
215 | strs[0] = "file.foo"; | |
216 | cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); | |
ac3d33df | 217 | cl_git_pass(git_index_write(index)); |
666ae188 | 218 | check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); |
f30fff45 RB |
219 | |
220 | /* add with check - should generate error */ | |
221 | error = git_index_add_all( | |
222 | index, &paths, GIT_INDEX_ADD_CHECK_PATHSPEC, NULL, NULL); | |
223 | cl_assert_equal_i(GIT_EINVALIDSPEC, error); | |
ac3d33df | 224 | cl_git_pass(git_index_write(index)); |
666ae188 | 225 | check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); |
f30fff45 RB |
226 | |
227 | /* add with force - should allow */ | |
228 | cl_git_pass(git_index_add_all( | |
229 | index, &paths, GIT_INDEX_ADD_FORCE, NULL, NULL)); | |
ac3d33df | 230 | cl_git_pass(git_index_write(index)); |
8b22d862 | 231 | check_stat_data(index, TEST_DIR "/file.foo", true); |
666ae188 | 232 | check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0); |
f30fff45 RB |
233 | |
234 | /* now it's in the index, so regular add should work */ | |
8b22d862 RB |
235 | cl_git_rewritefile(TEST_DIR "/file.foo", "new content for file"); |
236 | check_stat_data(index, TEST_DIR "/file.foo", false); | |
666ae188 | 237 | check_status(g_repo, 1, 0, 0, 3, 0, 1, 0, 0); |
f30fff45 RB |
238 | |
239 | cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); | |
ac3d33df | 240 | cl_git_pass(git_index_write(index)); |
8b22d862 | 241 | check_stat_data(index, TEST_DIR "/file.foo", true); |
666ae188 | 242 | check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0); |
f30fff45 RB |
243 | |
244 | cl_git_pass(git_index_add_bypath(index, "more.zzz")); | |
8b22d862 | 245 | check_stat_data(index, TEST_DIR "/more.zzz", true); |
666ae188 | 246 | check_status(g_repo, 2, 0, 0, 2, 0, 0, 0, 0); |
f30fff45 | 247 | |
8b22d862 | 248 | cl_git_rewritefile(TEST_DIR "/file.zzz", "new content for file"); |
666ae188 | 249 | check_status(g_repo, 2, 0, 0, 2, 0, 1, 0, 0); |
f30fff45 RB |
250 | |
251 | cl_git_pass(git_index_add_bypath(index, "file.zzz")); | |
8b22d862 | 252 | check_stat_data(index, TEST_DIR "/file.zzz", true); |
666ae188 | 253 | check_status(g_repo, 2, 0, 1, 2, 0, 0, 0, 0); |
f30fff45 RB |
254 | |
255 | strs[0] = "*.zzz"; | |
256 | cl_git_pass(git_index_remove_all(index, &paths, NULL, NULL)); | |
666ae188 | 257 | check_status(g_repo, 1, 1, 0, 4, 0, 0, 0, 0); |
f30fff45 RB |
258 | |
259 | cl_git_pass(git_index_add_bypath(index, "file.zzz")); | |
666ae188 | 260 | check_status(g_repo, 1, 0, 1, 3, 0, 0, 0, 0); |
f30fff45 | 261 | |
155fa234 | 262 | cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "second commit"); |
666ae188 | 263 | check_status(g_repo, 0, 0, 0, 3, 0, 0, 0, 0); |
f30fff45 | 264 | |
8b22d862 | 265 | cl_must_pass(p_unlink(TEST_DIR "/file.zzz")); |
666ae188 | 266 | check_status(g_repo, 0, 0, 0, 3, 1, 0, 0, 0); |
f30fff45 RB |
267 | |
268 | /* update_all should be able to remove entries */ | |
269 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
666ae188 | 270 | check_status(g_repo, 0, 1, 0, 3, 0, 0, 0, 0); |
f30fff45 | 271 | |
7863523a RB |
272 | strs[0] = "*"; |
273 | cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); | |
ac3d33df | 274 | cl_git_pass(git_index_write(index)); |
666ae188 | 275 | check_status(g_repo, 3, 1, 0, 0, 0, 0, 0, 0); |
7863523a RB |
276 | |
277 | /* must be able to remove at any position while still updating other files */ | |
8b22d862 RB |
278 | cl_must_pass(p_unlink(TEST_DIR "/.gitignore")); |
279 | cl_git_rewritefile(TEST_DIR "/file.zzz", "reconstructed file"); | |
280 | cl_git_rewritefile(TEST_DIR "/more.zzz", "altered file reality"); | |
666ae188 | 281 | check_status(g_repo, 3, 1, 0, 1, 1, 1, 0, 0); |
7863523a RB |
282 | |
283 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
666ae188 | 284 | check_status(g_repo, 2, 1, 0, 1, 0, 0, 0, 0); |
7863523a RB |
285 | /* this behavior actually matches 'git add -u' where "file.zzz" has |
286 | * been removed from the index, so when you go to update, even though | |
287 | * it exists in the HEAD, it is not re-added to the index, leaving it | |
288 | * as a DELETE when comparing HEAD to index and as an ADD comparing | |
289 | * index to worktree | |
290 | */ | |
291 | ||
f30fff45 RB |
292 | git_index_free(index); |
293 | } | |
8b22d862 | 294 | |
fa9a969d ET |
295 | void test_index_addall__files_in_folders(void) |
296 | { | |
297 | git_index *index; | |
fa9a969d ET |
298 | |
299 | addall_create_test_repo(true); | |
300 | ||
301 | cl_git_pass(git_repository_index(&index, g_repo)); | |
302 | ||
303 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 304 | cl_git_pass(git_index_write(index)); |
fa9a969d | 305 | check_stat_data(index, TEST_DIR "/file.bar", true); |
666ae188 | 306 | check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0); |
fa9a969d ET |
307 | |
308 | cl_must_pass(p_mkdir(TEST_DIR "/subdir", 0777)); | |
309 | cl_git_mkfile(TEST_DIR "/subdir/file", "hello!\n"); | |
666ae188 | 310 | check_status(g_repo, 2, 0, 0, 1, 0, 0, 1, 0); |
fa9a969d ET |
311 | |
312 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 313 | cl_git_pass(git_index_write(index)); |
666ae188 | 314 | check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0); |
fa9a969d ET |
315 | |
316 | git_index_free(index); | |
317 | } | |
318 | ||
bdec3363 ET |
319 | void test_index_addall__hidden_files(void) |
320 | { | |
c25aa7cd | 321 | #ifdef GIT_WIN32 |
bdec3363 ET |
322 | git_index *index; |
323 | ||
bdec3363 ET |
324 | addall_create_test_repo(true); |
325 | ||
326 | cl_git_pass(git_repository_index(&index, g_repo)); | |
327 | ||
328 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 329 | cl_git_pass(git_index_write(index)); |
bdec3363 ET |
330 | check_stat_data(index, TEST_DIR "/file.bar", true); |
331 | check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0); | |
332 | ||
333 | cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one"); | |
334 | cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one"); | |
335 | cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one"); | |
336 | ||
337 | check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0); | |
338 | ||
339 | cl_git_pass(git_win32__set_hidden(TEST_DIR "/file.zzz", true)); | |
340 | cl_git_pass(git_win32__set_hidden(TEST_DIR "/more.zzz", true)); | |
341 | cl_git_pass(git_win32__set_hidden(TEST_DIR "/other.zzz", true)); | |
342 | ||
343 | check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0); | |
344 | ||
345 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 346 | cl_git_pass(git_index_write(index)); |
bdec3363 ET |
347 | check_stat_data(index, TEST_DIR "/file.bar", true); |
348 | check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0); | |
349 | ||
350 | git_index_free(index); | |
351 | #endif | |
352 | } | |
353 | ||
8b22d862 RB |
354 | static int addall_match_prefix( |
355 | const char *path, const char *matched_pathspec, void *payload) | |
356 | { | |
357 | GIT_UNUSED(matched_pathspec); | |
358 | return !git__prefixcmp(path, payload) ? 0 : 1; | |
359 | } | |
360 | ||
361 | static int addall_match_suffix( | |
362 | const char *path, const char *matched_pathspec, void *payload) | |
363 | { | |
364 | GIT_UNUSED(matched_pathspec); | |
365 | return !git__suffixcmp(path, payload) ? 0 : 1; | |
366 | } | |
367 | ||
368 | static int addall_cancel_at( | |
369 | const char *path, const char *matched_pathspec, void *payload) | |
370 | { | |
371 | GIT_UNUSED(matched_pathspec); | |
372 | return !strcmp(path, payload) ? -123 : 0; | |
373 | } | |
374 | ||
375 | void test_index_addall__callback_filtering(void) | |
376 | { | |
377 | git_index *index; | |
378 | ||
379 | addall_create_test_repo(false); | |
380 | ||
381 | cl_git_pass(git_repository_index(&index, g_repo)); | |
382 | ||
383 | cl_git_pass( | |
384 | git_index_add_all(index, NULL, 0, addall_match_prefix, "file.")); | |
ac3d33df | 385 | cl_git_pass(git_index_write(index)); |
8b22d862 | 386 | check_stat_data(index, TEST_DIR "/file.bar", true); |
666ae188 | 387 | check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0); |
8b22d862 RB |
388 | |
389 | cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one"); | |
390 | cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one"); | |
391 | cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one"); | |
392 | ||
393 | cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); | |
394 | check_stat_data(index, TEST_DIR "/file.bar", true); | |
666ae188 | 395 | check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0); |
8b22d862 RB |
396 | |
397 | cl_git_pass( | |
398 | git_index_add_all(index, NULL, 0, addall_match_prefix, "other")); | |
ac3d33df | 399 | cl_git_pass(git_index_write(index)); |
8b22d862 | 400 | check_stat_data(index, TEST_DIR "/other.zzz", true); |
666ae188 | 401 | check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0); |
8b22d862 RB |
402 | |
403 | cl_git_pass( | |
404 | git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz")); | |
ac3d33df | 405 | cl_git_pass(git_index_write(index)); |
666ae188 | 406 | check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0); |
8b22d862 RB |
407 | |
408 | cl_git_pass( | |
409 | git_index_remove_all(index, NULL, addall_match_suffix, ".zzz")); | |
666ae188 | 410 | check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0); |
8b22d862 RB |
411 | |
412 | cl_git_fail_with( | |
413 | git_index_add_all(index, NULL, 0, addall_cancel_at, "more.zzz"), -123); | |
666ae188 | 414 | check_status(g_repo, 3, 0, 0, 2, 0, 0, 1, 0); |
8b22d862 RB |
415 | |
416 | cl_git_fail_with( | |
417 | git_index_add_all(index, NULL, 0, addall_cancel_at, "other.zzz"), -123); | |
666ae188 | 418 | check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0); |
8b22d862 RB |
419 | |
420 | cl_git_pass( | |
421 | git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz")); | |
ac3d33df | 422 | cl_git_pass(git_index_write(index)); |
666ae188 | 423 | check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0); |
8b22d862 RB |
424 | |
425 | cl_must_pass(p_unlink(TEST_DIR "/file.zzz")); | |
426 | cl_must_pass(p_unlink(TEST_DIR "/more.zzz")); | |
427 | cl_must_pass(p_unlink(TEST_DIR "/other.zzz")); | |
428 | ||
429 | cl_git_fail_with( | |
430 | git_index_update_all(index, NULL, addall_cancel_at, "more.zzz"), -123); | |
431 | /* file.zzz removed from index (so Index Adds 5 -> 4) and | |
432 | * more.zzz + other.zzz removed (so Worktree Dels 0 -> 2) */ | |
666ae188 | 433 | check_status(g_repo, 4, 0, 0, 0, 2, 0, 1, 0); |
8b22d862 RB |
434 | |
435 | cl_git_fail_with( | |
436 | git_index_update_all(index, NULL, addall_cancel_at, "other.zzz"), -123); | |
437 | /* more.zzz removed from index (so Index Adds 4 -> 3) and | |
438 | * Just other.zzz removed (so Worktree Dels 2 -> 1) */ | |
666ae188 | 439 | check_status(g_repo, 3, 0, 0, 0, 1, 0, 1, 0); |
8b22d862 RB |
440 | |
441 | git_index_free(index); | |
442 | } | |
666ae188 ET |
443 | |
444 | void test_index_addall__adds_conflicts(void) | |
445 | { | |
446 | git_index *index; | |
447 | git_reference *ref; | |
448 | git_annotated_commit *annotated; | |
449 | ||
450 | g_repo = cl_git_sandbox_init("merge-resolve"); | |
451 | cl_git_pass(git_repository_index(&index, g_repo)); | |
452 | ||
453 | check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0); | |
454 | ||
455 | cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch")); | |
456 | cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref)); | |
457 | ||
9f3c18e2 | 458 | cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL)); |
666ae188 ET |
459 | check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1); |
460 | ||
461 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 462 | cl_git_pass(git_index_write(index)); |
666ae188 ET |
463 | check_status(g_repo, 0, 1, 3, 0, 0, 0, 0, 0); |
464 | ||
465 | git_annotated_commit_free(annotated); | |
466 | git_reference_free(ref); | |
467 | git_index_free(index); | |
468 | } | |
469 | ||
470 | void test_index_addall__removes_deleted_conflicted_files(void) | |
471 | { | |
472 | git_index *index; | |
473 | git_reference *ref; | |
474 | git_annotated_commit *annotated; | |
475 | ||
476 | g_repo = cl_git_sandbox_init("merge-resolve"); | |
477 | cl_git_pass(git_repository_index(&index, g_repo)); | |
478 | ||
479 | check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0); | |
480 | ||
481 | cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch")); | |
482 | cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref)); | |
483 | ||
9f3c18e2 | 484 | cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL)); |
666ae188 ET |
485 | check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1); |
486 | ||
487 | cl_git_rmfile("merge-resolve/conflicting.txt"); | |
488 | ||
489 | cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); | |
ac3d33df | 490 | cl_git_pass(git_index_write(index)); |
666ae188 ET |
491 | check_status(g_repo, 0, 2, 2, 0, 0, 0, 0, 0); |
492 | ||
493 | git_annotated_commit_free(annotated); | |
494 | git_reference_free(ref); | |
495 | git_index_free(index); | |
eb29292a | 496 | } |