]> git.proxmox.com Git - libgit2.git/blame - tests/cherrypick/workdir.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / cherrypick / workdir.c
CommitLineData
103b7d21
JG
1#include "clar.h"
2#include "clar_libgit2.h"
3
22a2d3d5 4#include "futils.h"
103b7d21
JG
5#include "git2/cherrypick.h"
6
7#include "../merge/merge_helpers.h"
8
9#define TEST_REPO_PATH "cherrypick"
10
11static git_repository *repo;
12static git_index *repo_index;
13
ac3d33df 14/* Fixture setup and teardown */
103b7d21
JG
15void test_cherrypick_workdir__initialize(void)
16{
17 repo = cl_git_sandbox_init(TEST_REPO_PATH);
18 git_repository_index(&repo_index, repo);
19}
20
21void test_cherrypick_workdir__cleanup(void)
22{
23 git_index_free(repo_index);
24 cl_git_sandbox_cleanup();
25}
26
27/* git reset --hard d3d77487660ee3c0194ee01dc5eaf478782b1c7e
28 * git cherry-pick cfc4f0999a8367568e049af4f72e452d40828a15
29 * git cherry-pick 964ea3da044d9083181a88ba6701de9e35778bf4
30 * git cherry-pick a43a050c588d4e92f11a6b139680923e9728477d
31 */
32void test_cherrypick_workdir__automerge(void)
33{
34 git_oid head_oid;
35 git_signature *signature = NULL;
36 size_t i;
37
0ba4dca5 38 const char *cherrypick_oids[] = {
103b7d21
JG
39 "cfc4f0999a8367568e049af4f72e452d40828a15",
40 "964ea3da044d9083181a88ba6701de9e35778bf4",
41 "a43a050c588d4e92f11a6b139680923e9728477d",
42 };
43
44 struct merge_index_entry merge_index_entries[] = {
45 { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
46 { 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
47 { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
48
49 { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
50 { 0100644, "bd8fc3c59fb52d3c8b5907ace7defa5803f82419", 0, "file2.txt" },
51 { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
52
53 { 0100644, "f06427bee380364bc7e0cb26a9245158e4726ce0", 0, "file1.txt" },
54 { 0100644, "bd8fc3c59fb52d3c8b5907ace7defa5803f82419", 0, "file2.txt" },
55 { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
56 };
57
58 cl_git_pass(git_signature_new(&signature, "Picker", "picker@example.org", time(NULL), 0));
59
60 git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
61
62 for (i = 0; i < 3; ++i) {
63 git_commit *head = NULL, *commit = NULL;
0ba4dca5
ET
64 git_oid cherry_oid, cherrypicked_oid, cherrypicked_tree_oid;
65 git_tree *cherrypicked_tree = NULL;
103b7d21
JG
66
67 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 68 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21 69
0ba4dca5 70 git_oid_fromstr(&cherry_oid, cherrypick_oids[i]);
103b7d21 71 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
0ba4dca5 72 cl_git_pass(git_cherrypick(repo, commit, NULL));
103b7d21 73
e579e0f7
MB
74 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
75 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
103b7d21 76
0ba4dca5
ET
77 cl_git_pass(git_index_write_tree(&cherrypicked_tree_oid, repo_index));
78 cl_git_pass(git_tree_lookup(&cherrypicked_tree, repo, &cherrypicked_tree_oid));
79 cl_git_pass(git_commit_create(&cherrypicked_oid, repo, "HEAD", signature, signature, NULL,
80 "Cherry picked!", cherrypicked_tree, 1, (const git_commit **)&head));
103b7d21
JG
81
82 cl_assert(merge_test_index(repo_index, merge_index_entries + i * 3, 3));
83
0ba4dca5 84 git_oid_cpy(&head_oid, &cherrypicked_oid);
103b7d21 85
0ba4dca5 86 git_tree_free(cherrypicked_tree);
103b7d21
JG
87 git_commit_free(head);
88 git_commit_free(commit);
89 }
90
91 git_signature_free(signature);
92}
93
493c340c
JG
94/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
95 * git cherry-pick a43a050c588d4e92f11a6b139680923e9728477d*/
96void test_cherrypick_workdir__empty_result(void)
97{
98 git_oid head_oid;
99 git_signature *signature = NULL;
100 git_commit *head = NULL, *commit = NULL;
101 git_oid cherry_oid;
102
103 const char *cherrypick_oid = "a43a050c588d4e92f11a6b139680923e9728477d";
104
105 struct merge_index_entry merge_index_entries[] = {
106 { 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" },
107 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" },
108 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 0, "file3.txt" },
109 };
110
111 cl_git_pass(git_signature_new(&signature, "Picker", "picker@example.org", time(NULL), 0));
112
113 git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
114
115 /* Create an untracked file that should not conflict */
116 cl_git_mkfile(TEST_REPO_PATH "/file4.txt", "");
e579e0f7 117 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/file4.txt"));
493c340c
JG
118
119 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 120 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
493c340c
JG
121
122 git_oid_fromstr(&cherry_oid, cherrypick_oid);
123 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
124 cl_git_pass(git_cherrypick(repo, commit, NULL));
125
126 /* The resulting tree should not have changed, the change was already on HEAD */
127 cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
128
129 git_commit_free(head);
130 git_commit_free(commit);
131
132 git_signature_free(signature);
133}
134
103b7d21
JG
135/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
136 * git cherry-pick e9b63f3655b2ad80c0ff587389b5a9589a3a7110
137 */
138void test_cherrypick_workdir__conflicts(void)
139{
140 git_commit *head = NULL, *commit = NULL;
141 git_oid head_oid, cherry_oid;
e579e0f7 142 git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
103b7d21
JG
143
144 struct merge_index_entry merge_index_entries[] = {
145 { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
146 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
147 { 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
148 { 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
149 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
150 { 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
151 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
152 };
153
154 git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
155
156 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 157 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
158
159 git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
160 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
0ba4dca5 161 cl_git_pass(git_cherrypick(repo, commit, NULL));
103b7d21 162
e579e0f7
MB
163 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
164 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
103b7d21
JG
165
166 cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
167
168 cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
169 TEST_REPO_PATH "/.git/MERGE_MSG"));
e579e0f7 170 cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
103b7d21
JG
171 "Change all files\n" \
172 "\n" \
e579e0f7
MB
173 "#Conflicts:\n" \
174 "#\tfile2.txt\n" \
175 "#\tfile3.txt\n") == 0);
103b7d21
JG
176
177 cl_git_pass(git_futils_readbuffer(&conflicting_buf,
178 TEST_REPO_PATH "/file2.txt"));
179
e579e0f7 180 cl_assert(strcmp(git_str_cstr(&conflicting_buf),
103b7d21
JG
181 "!File 2\n" \
182 "File 2\n" \
183 "File 2\n" \
184 "File 2\n" \
185 "File 2\n" \
186 "File 2\n" \
187 "File 2\n" \
188 "File 2\n" \
189 "File 2\n" \
190 "File 2\n" \
191 "File 2!!\n" \
192 "File 2\n" \
193 "File 2\n" \
194 "File 2\n" \
195 "<<<<<<< HEAD\n" \
196 "File 2\n" \
197 "=======\n" \
198 "File 2!\n" \
199 "File 2\n" \
200 "File 2!\n" \
201 ">>>>>>> e9b63f3... Change all files\n") == 0);
202
203 cl_git_pass(git_futils_readbuffer(&conflicting_buf,
204 TEST_REPO_PATH "/file3.txt"));
205
e579e0f7 206 cl_assert(strcmp(git_str_cstr(&conflicting_buf),
103b7d21
JG
207 "!File 3\n" \
208 "File 3\n" \
209 "File 3\n" \
210 "File 3\n" \
211 "File 3\n" \
212 "File 3\n" \
213 "File 3\n" \
214 "File 3\n" \
215 "File 3\n" \
216 "File 3\n" \
217 "File 3\n" \
218 "File 3!!\n" \
219 "File 3\n" \
220 "File 3\n" \
221 "File 3\n" \
222 "<<<<<<< HEAD\n" \
223 "=======\n" \
224 "File 3!\n" \
225 "File 3!\n" \
226 ">>>>>>> e9b63f3... Change all files\n") == 0);
227
228 git_commit_free(commit);
229 git_commit_free(head);
e579e0f7
MB
230 git_str_dispose(&mergemsg_buf);
231 git_str_dispose(&conflicting_buf);
103b7d21
JG
232}
233
234/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
235 * git cherry-pick -X ours e9b63f3655b2ad80c0ff587389b5a9589a3a7110
236 */
237void test_cherrypick_workdir__conflict_use_ours(void)
238{
239 git_commit *head = NULL, *commit = NULL;
240 git_oid head_oid, cherry_oid;
0ba4dca5 241 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
242
243 struct merge_index_entry merge_index_entries[] = {
244 { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
245 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
246 { 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
247 { 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
248 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
249 { 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
250 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
251 };
252
253 struct merge_index_entry merge_filesystem_entries[] = {
254 { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
255 { 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 0, "file2.txt" },
256 { 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 0, "file3.txt" },
257 };
258
259 /* leave the index in a conflicted state, but checkout "ours" to the workdir */
260 opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
261
262 git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
263
264 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 265 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
266
267 git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
268 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
0ba4dca5 269 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
270
271 cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
272 cl_assert(merge_test_workdir(repo, merge_filesystem_entries, 3));
273
274 /* resolve conflicts in the index by taking "ours" */
275 opts.merge_opts.file_favor = GIT_MERGE_FILE_FAVOR_OURS;
276
23a17803 277 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
0ba4dca5 278 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
279
280 cl_assert(merge_test_index(repo_index, merge_filesystem_entries, 3));
281 cl_assert(merge_test_workdir(repo, merge_filesystem_entries, 3));
282
283 git_commit_free(commit);
284 git_commit_free(head);
285}
286
287/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
288 * git cherry-pick 2a26c7e88b285613b302ba76712bc998863f3cbc
289 */
290void test_cherrypick_workdir__rename(void)
291{
292 git_commit *head, *commit;
293 git_oid head_oid, cherry_oid;
0ba4dca5 294 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
295
296 struct merge_index_entry merge_index_entries[] = {
297 { 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" },
298 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" },
299 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 0, "file3.txt.renamed" },
300 };
301
fa78782f 302 opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
103b7d21
JG
303 opts.merge_opts.rename_threshold = 50;
304
305 git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
306 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 307 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
308
309 git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
310 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
0ba4dca5 311 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
312
313 cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
314
315 git_commit_free(commit);
316 git_commit_free(head);
317}
318
319/* git reset --hard 44cd2ed2052c9c68f9a439d208e9614dc2a55c70
320 * git cherry-pick 2a26c7e88b285613b302ba76712bc998863f3cbc
321 */
322void test_cherrypick_workdir__both_renamed(void)
323{
324 git_commit *head, *commit;
325 git_oid head_oid, cherry_oid;
e579e0f7 326 git_str mergemsg_buf = GIT_STR_INIT;
0ba4dca5 327 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
328
329 struct merge_index_entry merge_index_entries[] = {
330 { 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" },
331 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" },
332 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 1, "file3.txt" },
333 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt.renamed" },
334 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 2, "file3.txt.renamed_on_branch" },
335 };
336
fa78782f 337 opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
103b7d21
JG
338 opts.merge_opts.rename_threshold = 50;
339
340 git_oid_fromstr(&head_oid, "44cd2ed2052c9c68f9a439d208e9614dc2a55c70");
341 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 342 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
343
344 git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
345 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
0ba4dca5 346 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
347
348 cl_assert(merge_test_index(repo_index, merge_index_entries, 5));
349
350 cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
351 TEST_REPO_PATH "/.git/MERGE_MSG"));
e579e0f7 352 cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
103b7d21
JG
353 "Renamed file3.txt -> file3.txt.renamed\n" \
354 "\n" \
e579e0f7
MB
355 "#Conflicts:\n" \
356 "#\tfile3.txt\n" \
357 "#\tfile3.txt.renamed\n" \
358 "#\tfile3.txt.renamed_on_branch\n") == 0);
103b7d21 359
e579e0f7 360 git_str_dispose(&mergemsg_buf);
103b7d21
JG
361 git_commit_free(commit);
362 git_commit_free(head);
363}
364
365void test_cherrypick_workdir__nonmerge_fails_mainline_specified(void)
366{
367 git_reference *head;
368 git_commit *commit;
0ba4dca5 369 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
370
371 cl_git_pass(git_repository_head(&head, repo));
ac3d33df 372 cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJECT_COMMIT));
103b7d21
JG
373
374 opts.mainline = 1;
0ba4dca5 375 cl_must_fail(git_cherrypick(repo, commit, &opts));
e579e0f7
MB
376 cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
377 cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
103b7d21
JG
378
379 git_reference_free(head);
380 git_commit_free(commit);
381}
382
383/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
384 * git cherry-pick abe4603bc7cd5b8167a267e0e2418fd2348f8cff
385 */
386void test_cherrypick_workdir__merge_fails_without_mainline_specified(void)
387{
388 git_commit *head, *commit;
389 git_oid head_oid, cherry_oid;
390
391 git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
392 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 393 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
394
395 git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
396 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
397
0ba4dca5 398 cl_must_fail(git_cherrypick(repo, commit, NULL));
e579e0f7
MB
399 cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
400 cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
103b7d21
JG
401
402 git_commit_free(commit);
403 git_commit_free(head);
404}
405
406/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
407 * git cherry-pick -m1 abe4603bc7cd5b8167a267e0e2418fd2348f8cff
408 */
409void test_cherrypick_workdir__merge_first_parent(void)
410{
411 git_commit *head, *commit;
412 git_oid head_oid, cherry_oid;
0ba4dca5 413 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
414
415 struct merge_index_entry merge_index_entries[] = {
416 { 0100644, "f90f9dcbdac2cce5cc166346160e19cb693ef4e8", 0, "file1.txt" },
417 { 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 0, "file2.txt" },
418 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 0, "file3.txt" },
419 };
420
421 opts.mainline = 1;
422
423 git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
424 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 425 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
426
427 git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
428 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
429
0ba4dca5 430 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
431
432 cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
433
434 git_commit_free(commit);
435 git_commit_free(head);
436}
437
438/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
439 * git cherry-pick -m2 abe4603bc7cd5b8167a267e0e2418fd2348f8cff
440 */
441void test_cherrypick_workdir__merge_second_parent(void)
442{
443 git_commit *head, *commit;
444 git_oid head_oid, cherry_oid;
0ba4dca5 445 git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
103b7d21
JG
446
447 struct merge_index_entry merge_index_entries[] = {
448 { 0100644, "487434cace79238a7091e2220611d4f20a765690", 0, "file1.txt" },
449 { 0100644, "e5183bfd18e3a0a691fadde2f0d5610b73282d31", 0, "file2.txt" },
450 { 0100644, "409a1bec58bf35348e8b62b72bb9c1f45cf5a587", 0, "file3.txt" },
451 };
452
453 opts.mainline = 2;
454
455 git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
456 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
23a17803 457 cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
103b7d21
JG
458
459 git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
460 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
461
0ba4dca5 462 cl_git_pass(git_cherrypick(repo, commit, &opts));
103b7d21
JG
463
464 cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
465
466 git_commit_free(commit);
467 git_commit_free(head);
468}
469