]> git.proxmox.com Git - libgit2.git/blame - tests/index/addall.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / index / addall.c
CommitLineData
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 6static git_repository *g_repo = NULL;
8b22d862 7#define TEST_DIR "addall"
f30fff45
RB
8
9void test_index_addall__initialize(void)
10{
11}
12
13void 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
28typedef 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
39static 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 74static 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
107static 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
140static 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
160void 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
295void 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
319void test_index_addall__hidden_files(void)
320{
321 git_index *index;
322
323 GIT_UNUSED(index);
324
325#ifdef GIT_WIN32
326 addall_create_test_repo(true);
327
328 cl_git_pass(git_repository_index(&index, g_repo));
329
330 cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
ac3d33df 331 cl_git_pass(git_index_write(index));
bdec3363
ET
332 check_stat_data(index, TEST_DIR "/file.bar", true);
333 check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0);
334
335 cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
336 cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
337 cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
338
339 check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
340
341 cl_git_pass(git_win32__set_hidden(TEST_DIR "/file.zzz", true));
342 cl_git_pass(git_win32__set_hidden(TEST_DIR "/more.zzz", true));
343 cl_git_pass(git_win32__set_hidden(TEST_DIR "/other.zzz", true));
344
345 check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
346
347 cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
ac3d33df 348 cl_git_pass(git_index_write(index));
bdec3363
ET
349 check_stat_data(index, TEST_DIR "/file.bar", true);
350 check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0);
351
352 git_index_free(index);
353#endif
354}
355
8b22d862
RB
356static int addall_match_prefix(
357 const char *path, const char *matched_pathspec, void *payload)
358{
359 GIT_UNUSED(matched_pathspec);
360 return !git__prefixcmp(path, payload) ? 0 : 1;
361}
362
363static int addall_match_suffix(
364 const char *path, const char *matched_pathspec, void *payload)
365{
366 GIT_UNUSED(matched_pathspec);
367 return !git__suffixcmp(path, payload) ? 0 : 1;
368}
369
370static int addall_cancel_at(
371 const char *path, const char *matched_pathspec, void *payload)
372{
373 GIT_UNUSED(matched_pathspec);
374 return !strcmp(path, payload) ? -123 : 0;
375}
376
377void test_index_addall__callback_filtering(void)
378{
379 git_index *index;
380
381 addall_create_test_repo(false);
382
383 cl_git_pass(git_repository_index(&index, g_repo));
384
385 cl_git_pass(
386 git_index_add_all(index, NULL, 0, addall_match_prefix, "file."));
ac3d33df 387 cl_git_pass(git_index_write(index));
8b22d862 388 check_stat_data(index, TEST_DIR "/file.bar", true);
666ae188 389 check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0);
8b22d862
RB
390
391 cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
392 cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
393 cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
394
395 cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
396 check_stat_data(index, TEST_DIR "/file.bar", true);
666ae188 397 check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0);
8b22d862
RB
398
399 cl_git_pass(
400 git_index_add_all(index, NULL, 0, addall_match_prefix, "other"));
ac3d33df 401 cl_git_pass(git_index_write(index));
8b22d862 402 check_stat_data(index, TEST_DIR "/other.zzz", true);
666ae188 403 check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
8b22d862
RB
404
405 cl_git_pass(
406 git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
ac3d33df 407 cl_git_pass(git_index_write(index));
666ae188 408 check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0);
8b22d862
RB
409
410 cl_git_pass(
411 git_index_remove_all(index, NULL, addall_match_suffix, ".zzz"));
666ae188 412 check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0);
8b22d862
RB
413
414 cl_git_fail_with(
415 git_index_add_all(index, NULL, 0, addall_cancel_at, "more.zzz"), -123);
666ae188 416 check_status(g_repo, 3, 0, 0, 2, 0, 0, 1, 0);
8b22d862
RB
417
418 cl_git_fail_with(
419 git_index_add_all(index, NULL, 0, addall_cancel_at, "other.zzz"), -123);
666ae188 420 check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0);
8b22d862
RB
421
422 cl_git_pass(
423 git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
ac3d33df 424 cl_git_pass(git_index_write(index));
666ae188 425 check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0);
8b22d862
RB
426
427 cl_must_pass(p_unlink(TEST_DIR "/file.zzz"));
428 cl_must_pass(p_unlink(TEST_DIR "/more.zzz"));
429 cl_must_pass(p_unlink(TEST_DIR "/other.zzz"));
430
431 cl_git_fail_with(
432 git_index_update_all(index, NULL, addall_cancel_at, "more.zzz"), -123);
433 /* file.zzz removed from index (so Index Adds 5 -> 4) and
434 * more.zzz + other.zzz removed (so Worktree Dels 0 -> 2) */
666ae188 435 check_status(g_repo, 4, 0, 0, 0, 2, 0, 1, 0);
8b22d862
RB
436
437 cl_git_fail_with(
438 git_index_update_all(index, NULL, addall_cancel_at, "other.zzz"), -123);
439 /* more.zzz removed from index (so Index Adds 4 -> 3) and
440 * Just other.zzz removed (so Worktree Dels 2 -> 1) */
666ae188 441 check_status(g_repo, 3, 0, 0, 0, 1, 0, 1, 0);
8b22d862
RB
442
443 git_index_free(index);
444}
666ae188
ET
445
446void test_index_addall__adds_conflicts(void)
447{
448 git_index *index;
449 git_reference *ref;
450 git_annotated_commit *annotated;
451
452 g_repo = cl_git_sandbox_init("merge-resolve");
453 cl_git_pass(git_repository_index(&index, g_repo));
454
455 check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);
456
457 cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch"));
458 cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref));
459
9f3c18e2 460 cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL));
666ae188
ET
461 check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1);
462
463 cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
ac3d33df 464 cl_git_pass(git_index_write(index));
666ae188
ET
465 check_status(g_repo, 0, 1, 3, 0, 0, 0, 0, 0);
466
467 git_annotated_commit_free(annotated);
468 git_reference_free(ref);
469 git_index_free(index);
470}
471
472void test_index_addall__removes_deleted_conflicted_files(void)
473{
474 git_index *index;
475 git_reference *ref;
476 git_annotated_commit *annotated;
477
478 g_repo = cl_git_sandbox_init("merge-resolve");
479 cl_git_pass(git_repository_index(&index, g_repo));
480
481 check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);
482
483 cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch"));
484 cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref));
485
9f3c18e2 486 cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL));
666ae188
ET
487 check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1);
488
489 cl_git_rmfile("merge-resolve/conflicting.txt");
490
491 cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
ac3d33df 492 cl_git_pass(git_index_write(index));
666ae188
ET
493 check_status(g_repo, 0, 2, 2, 0, 0, 0, 0, 0);
494
495 git_annotated_commit_free(annotated);
496 git_reference_free(ref);
497 git_index_free(index);
eb29292a 498}