1 #include "clar_libgit2.h"
4 static git_repository
*_repo
;
6 void test_object_tree_duplicateentries__initialize(void) {
7 _repo
= cl_git_sandbox_init("testrepo");
10 void test_object_tree_duplicateentries__cleanup(void) {
11 cl_git_sandbox_cleanup();
15 * $ git show --format=raw refs/heads/dir
16 * commit 144344043ba4d4a405da03de3844aa829ae8be0e
17 * tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
18 * parent cf80f8de9f1185bf3a05f993f6121880dd0cfbc9
19 * author Ben Straub <bstraub@github.com> 1343755506 -0700
20 * committer Ben Straub <bstraub@github.com> 1343755506 -0700
24 * diff --git a/a/b.txt b/a/b.txt
28 * $ git ls-tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
29 * 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README
30 * 040000 tree 4e0883eeeeebc1fb1735161cea82f7cb5fab7e63 a
31 * 100644 blob 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 branch_file.txt
32 * 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt
35 static void tree_checker(
37 const char *expected_sha
,
38 git_filemode_t expected_filemode
)
41 const git_tree_entry
*entry
;
44 cl_git_pass(git_tree_lookup(&tree
, _repo
, tid
));
45 cl_assert_equal_i(1, (int)git_tree_entrycount(tree
));
46 entry
= git_tree_entry_byindex(tree
, 0);
48 cl_git_pass(git_oid_fromstr(&oid
, expected_sha
));
50 cl_assert_equal_i(0, git_oid_cmp(&oid
, git_tree_entry_id(entry
)));
51 cl_assert_equal_i(expected_filemode
, git_tree_entry_filemode(entry
));
56 static void tree_creator(git_oid
*out
, void (*fn
)(git_treebuilder
*))
58 git_treebuilder
*builder
;
60 cl_git_pass(git_treebuilder_new(&builder
, _repo
, NULL
));
64 cl_git_pass(git_treebuilder_write(out
, builder
));
65 git_treebuilder_free(builder
);
68 static void two_blobs(git_treebuilder
*bld
)
71 const git_tree_entry
*entry
;
73 cl_git_pass(git_oid_fromstr(&oid
,
74 "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
76 cl_git_pass(git_treebuilder_insert(
77 &entry
, bld
, "duplicate", &oid
,
80 cl_git_pass(git_oid_fromstr(&oid
,
81 "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); /* blob oid (new.txt) */
83 cl_git_pass(git_treebuilder_insert(
84 &entry
, bld
, "duplicate", &oid
,
88 static void one_blob_and_one_tree(git_treebuilder
*bld
)
91 const git_tree_entry
*entry
;
93 cl_git_pass(git_oid_fromstr(&oid
,
94 "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
96 cl_git_pass(git_treebuilder_insert(
97 &entry
, bld
, "duplicate", &oid
,
100 cl_git_pass(git_oid_fromstr(&oid
,
101 "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63")); /* tree oid (a) */
103 cl_git_pass(git_treebuilder_insert(
104 &entry
, bld
, "duplicate", &oid
,
108 void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_through_the_treebuilder(void)
112 tree_creator(&tid
, two_blobs
);
113 tree_checker(&tid
, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_FILEMODE_BLOB
);
115 tree_creator(&tid
, one_blob_and_one_tree
);
116 tree_checker(&tid
, "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63", GIT_FILEMODE_TREE
);
119 static void add_fake_conflicts(git_index
*index
)
121 git_index_entry ancestor_entry
, our_entry
, their_entry
;
123 memset(&ancestor_entry
, 0x0, sizeof(git_index_entry
));
124 memset(&our_entry
, 0x0, sizeof(git_index_entry
));
125 memset(&their_entry
, 0x0, sizeof(git_index_entry
));
127 ancestor_entry
.path
= "duplicate";
128 ancestor_entry
.mode
= GIT_FILEMODE_BLOB
;
129 GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry
, 1);
130 git_oid_fromstr(&ancestor_entry
.id
, "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
132 our_entry
.path
= "duplicate";
133 our_entry
.mode
= GIT_FILEMODE_BLOB
;
134 GIT_INDEX_ENTRY_STAGE_SET(&our_entry
, 2);
135 git_oid_fromstr(&our_entry
.id
, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
137 their_entry
.path
= "duplicate";
138 their_entry
.mode
= GIT_FILEMODE_BLOB
;
139 GIT_INDEX_ENTRY_STAGE_SET(&their_entry
, 3);
140 git_oid_fromstr(&their_entry
.id
, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
142 cl_git_pass(git_index_conflict_add(index
, &ancestor_entry
, &our_entry
, &their_entry
));
145 void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_building_a_tree_from_a_index_with_conflicts(void)
150 cl_git_pass(git_repository_index(&index
, _repo
));
152 add_fake_conflicts(index
);
154 cl_assert_equal_i(GIT_EUNMERGED
, git_index_write_tree(&tid
, index
));
156 git_index_free(index
);