]>
Commit | Line | Data |
---|---|---|
103b7d21 JG |
1 | #include "clar.h" |
2 | #include "clar_libgit2.h" | |
3 | ||
4 | #include "buffer.h" | |
22a2d3d5 | 5 | #include "futils.h" |
103b7d21 JG |
6 | #include "git2/cherrypick.h" |
7 | ||
8 | #include "../merge/merge_helpers.h" | |
9 | ||
10 | #define TEST_REPO_PATH "cherrypick" | |
11 | ||
12 | static git_repository *repo; | |
13 | ||
14 | void test_cherrypick_bare__initialize(void) | |
15 | { | |
16 | repo = cl_git_sandbox_init(TEST_REPO_PATH); | |
17 | } | |
18 | ||
19 | void test_cherrypick_bare__cleanup(void) | |
20 | { | |
21 | cl_git_sandbox_cleanup(); | |
22 | } | |
23 | ||
24 | void test_cherrypick_bare__automerge(void) | |
25 | { | |
26 | git_commit *head = NULL, *commit = NULL; | |
27 | git_index *index = NULL; | |
28 | git_oid head_oid, cherry_oid; | |
29 | ||
30 | struct merge_index_entry merge_index_entries[] = { | |
31 | { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" }, | |
32 | { 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" }, | |
33 | { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" }, | |
34 | }; | |
35 | ||
36 | git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e"); | |
37 | cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); | |
38 | ||
39 | git_oid_fromstr(&cherry_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); | |
40 | cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); | |
41 | ||
0ba4dca5 | 42 | cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); |
103b7d21 JG |
43 | cl_assert(merge_test_index(index, merge_index_entries, 3)); |
44 | ||
45 | git_index_free(index); | |
46 | git_commit_free(head); | |
47 | git_commit_free(commit); | |
48 | } | |
49 | ||
50 | void test_cherrypick_bare__conflicts(void) | |
51 | { | |
52 | git_commit *head = NULL, *commit = NULL; | |
53 | git_index *index = NULL; | |
54 | git_oid head_oid, cherry_oid; | |
55 | ||
56 | struct merge_index_entry merge_index_entries[] = { | |
57 | { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" }, | |
58 | { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" }, | |
59 | { 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" }, | |
60 | { 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" }, | |
61 | { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" }, | |
62 | { 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" }, | |
63 | { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" }, | |
64 | }; | |
65 | ||
66 | git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8"); | |
67 | cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); | |
68 | ||
69 | git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110"); | |
70 | cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); | |
71 | ||
0ba4dca5 | 72 | cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); |
103b7d21 JG |
73 | cl_assert(merge_test_index(index, merge_index_entries, 7)); |
74 | ||
75 | git_index_free(index); | |
76 | git_commit_free(head); | |
77 | git_commit_free(commit); | |
78 | } | |
79 | ||
80 | void test_cherrypick_bare__orphan(void) | |
81 | { | |
82 | git_commit *head = NULL, *commit = NULL; | |
83 | git_index *index = NULL; | |
84 | git_oid head_oid, cherry_oid; | |
85 | ||
86 | struct merge_index_entry merge_index_entries[] = { | |
87 | { 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" }, | |
88 | { 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" }, | |
89 | { 0100644, "85a4a1d791973644f24c72f5e89420d3064cc452", 0, "file3.txt" }, | |
90 | { 0100644, "9ccb9bf50c011fd58dcbaa65df917bf79539717f", 0, "orphan.txt" }, | |
91 | }; | |
92 | ||
93 | git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e"); | |
94 | cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); | |
95 | ||
96 | git_oid_fromstr(&cherry_oid, "74f06b5bfec6d33d7264f73606b57a7c0b963819"); | |
97 | cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); | |
98 | ||
0ba4dca5 | 99 | cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); |
103b7d21 JG |
100 | cl_assert(merge_test_index(index, merge_index_entries, 4)); |
101 | ||
102 | git_index_free(index); | |
103 | git_commit_free(head); | |
104 | git_commit_free(commit); | |
105 | } | |
106 |