2 #include "clar_libgit2.h"
5 #include "git2/cherrypick.h"
7 #include "../merge/merge_helpers.h"
9 #define TEST_REPO_PATH "cherrypick"
11 static git_repository
*repo
;
13 void test_cherrypick_bare__initialize(void)
15 repo
= cl_git_sandbox_init(TEST_REPO_PATH
);
18 void test_cherrypick_bare__cleanup(void)
20 cl_git_sandbox_cleanup();
23 void test_cherrypick_bare__automerge(void)
25 git_commit
*head
= NULL
, *commit
= NULL
;
26 git_index
*index
= NULL
;
27 git_oid head_oid
, cherry_oid
;
29 struct merge_index_entry merge_index_entries
[] = {
30 { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
31 { 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
32 { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
35 git_oid_fromstr(&head_oid
, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
36 cl_git_pass(git_commit_lookup(&head
, repo
, &head_oid
));
38 git_oid_fromstr(&cherry_oid
, "cfc4f0999a8367568e049af4f72e452d40828a15");
39 cl_git_pass(git_commit_lookup(&commit
, repo
, &cherry_oid
));
41 cl_git_pass(git_cherrypick_commit(&index
, repo
, commit
, head
, 0, NULL
));
42 cl_assert(merge_test_index(index
, merge_index_entries
, 3));
44 git_index_free(index
);
45 git_commit_free(head
);
46 git_commit_free(commit
);
49 void test_cherrypick_bare__conflicts(void)
51 git_commit
*head
= NULL
, *commit
= NULL
;
52 git_index
*index
= NULL
;
53 git_oid head_oid
, cherry_oid
;
55 struct merge_index_entry merge_index_entries
[] = {
56 { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
57 { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
58 { 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
59 { 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
60 { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
61 { 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
62 { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
65 git_oid_fromstr(&head_oid
, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
66 cl_git_pass(git_commit_lookup(&head
, repo
, &head_oid
));
68 git_oid_fromstr(&cherry_oid
, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
69 cl_git_pass(git_commit_lookup(&commit
, repo
, &cherry_oid
));
71 cl_git_pass(git_cherrypick_commit(&index
, repo
, commit
, head
, 0, NULL
));
72 cl_assert(merge_test_index(index
, merge_index_entries
, 7));
74 git_index_free(index
);
75 git_commit_free(head
);
76 git_commit_free(commit
);
79 void test_cherrypick_bare__orphan(void)
81 git_commit
*head
= NULL
, *commit
= NULL
;
82 git_index
*index
= NULL
;
83 git_oid head_oid
, cherry_oid
;
85 struct merge_index_entry merge_index_entries
[] = {
86 { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
87 { 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
88 { 0100644, "85a4a1d791973644f24c72f5e89420d3064cc452", 0, "file3.txt" },
89 { 0100644, "9ccb9bf50c011fd58dcbaa65df917bf79539717f", 0, "orphan.txt" },
92 git_oid_fromstr(&head_oid
, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
93 cl_git_pass(git_commit_lookup(&head
, repo
, &head_oid
));
95 git_oid_fromstr(&cherry_oid
, "74f06b5bfec6d33d7264f73606b57a7c0b963819");
96 cl_git_pass(git_commit_lookup(&commit
, repo
, &cherry_oid
));
98 cl_git_pass(git_cherrypick_commit(&index
, repo
, commit
, head
, 0, NULL
));
99 cl_assert(merge_test_index(index
, merge_index_entries
, 4));
101 git_index_free(index
);
102 git_commit_free(head
);
103 git_commit_free(commit
);