]> git.proxmox.com Git - libgit2.git/blob - tests/cherrypick/bare.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / cherrypick / bare.c
1 #include "clar.h"
2 #include "clar_libgit2.h"
3
4 #include "futils.h"
5 #include "git2/cherrypick.h"
6
7 #include "../merge/merge_helpers.h"
8
9 #define TEST_REPO_PATH "cherrypick"
10
11 static git_repository *repo;
12
13 void test_cherrypick_bare__initialize(void)
14 {
15 repo = cl_git_sandbox_init(TEST_REPO_PATH);
16 }
17
18 void test_cherrypick_bare__cleanup(void)
19 {
20 cl_git_sandbox_cleanup();
21 }
22
23 void test_cherrypick_bare__automerge(void)
24 {
25 git_commit *head = NULL, *commit = NULL;
26 git_index *index = NULL;
27 git_oid head_oid, cherry_oid;
28
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" },
33 };
34
35 git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
36 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
37
38 git_oid_fromstr(&cherry_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
39 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
40
41 cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL));
42 cl_assert(merge_test_index(index, merge_index_entries, 3));
43
44 git_index_free(index);
45 git_commit_free(head);
46 git_commit_free(commit);
47 }
48
49 void test_cherrypick_bare__conflicts(void)
50 {
51 git_commit *head = NULL, *commit = NULL;
52 git_index *index = NULL;
53 git_oid head_oid, cherry_oid;
54
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" },
63 };
64
65 git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
66 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
67
68 git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
69 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
70
71 cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL));
72 cl_assert(merge_test_index(index, merge_index_entries, 7));
73
74 git_index_free(index);
75 git_commit_free(head);
76 git_commit_free(commit);
77 }
78
79 void test_cherrypick_bare__orphan(void)
80 {
81 git_commit *head = NULL, *commit = NULL;
82 git_index *index = NULL;
83 git_oid head_oid, cherry_oid;
84
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" },
90 };
91
92 git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
93 cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
94
95 git_oid_fromstr(&cherry_oid, "74f06b5bfec6d33d7264f73606b57a7c0b963819");
96 cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
97
98 cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL));
99 cl_assert(merge_test_index(index, merge_index_entries, 4));
100
101 git_index_free(index);
102 git_commit_free(head);
103 git_commit_free(commit);
104 }
105