]>
git.proxmox.com Git - libgit2.git/blob - tests/index/collision.c
1 #include "clar_libgit2.h"
2 #include "git2/repository.h"
3 #include "git2/index.h"
5 static git_repository
*g_repo
;
7 static git_index
*g_index
;
8 static git_oid g_empty_id
;
10 void test_index_collision__initialize(void)
12 g_repo
= cl_git_sandbox_init("empty_standard_repo");
13 cl_git_pass(git_repository_odb(&g_odb
, g_repo
));
14 cl_git_pass(git_repository_index(&g_index
, g_repo
));
16 cl_git_pass(git_odb_write(&g_empty_id
, g_odb
, "", 0, GIT_OBJECT_BLOB
));
19 void test_index_collision__cleanup(void)
21 git_index_free(g_index
);
23 cl_git_sandbox_cleanup();
26 void test_index_collision__add_blob_with_conflicting_file(void)
28 git_index_entry entry
;
29 git_tree_entry
*tentry
;
33 memset(&entry
, 0, sizeof(entry
));
34 entry
.ctime
.seconds
= 12346789;
35 entry
.mtime
.seconds
= 12346789;
38 git_oid_cpy(&entry
.id
, &g_empty_id
);
41 cl_git_pass(git_index_add(g_index
, &entry
));
43 /* Check a/b exists here */
44 cl_git_pass(git_index_write_tree(&tree_id
, g_index
));
45 cl_git_pass(git_tree_lookup(&tree
, g_repo
, &tree_id
));
46 cl_git_pass(git_tree_entry_bypath(&tentry
, tree
, "a/b"));
47 git_tree_entry_free(tentry
);
50 /* create a tree/blob collision */
52 cl_git_pass(git_index_add(g_index
, &entry
));
54 /* a/b should now be a tree and a/b/c a blob */
55 cl_git_pass(git_index_write_tree(&tree_id
, g_index
));
56 cl_git_pass(git_tree_lookup(&tree
, g_repo
, &tree_id
));
57 cl_git_pass(git_tree_entry_bypath(&tentry
, tree
, "a/b/c"));
58 git_tree_entry_free(tentry
);
62 void test_index_collision__add_blob_with_conflicting_dir(void)
64 git_index_entry entry
;
65 git_tree_entry
*tentry
;
69 memset(&entry
, 0, sizeof(entry
));
70 entry
.ctime
.seconds
= 12346789;
71 entry
.mtime
.seconds
= 12346789;
74 git_oid_cpy(&entry
.id
, &g_empty_id
);
77 cl_git_pass(git_index_add(g_index
, &entry
));
79 /* Check a/b/c exists here */
80 cl_git_pass(git_index_write_tree(&tree_id
, g_index
));
81 cl_git_pass(git_tree_lookup(&tree
, g_repo
, &tree_id
));
82 cl_git_pass(git_tree_entry_bypath(&tentry
, tree
, "a/b/c"));
83 git_tree_entry_free(tentry
);
86 /* create a blob/tree collision */
88 cl_git_pass(git_index_add(g_index
, &entry
));
90 /* a/b should now be a tree and a/b/c a blob */
91 cl_git_pass(git_index_write_tree(&tree_id
, g_index
));
92 cl_git_pass(git_tree_lookup(&tree
, g_repo
, &tree_id
));
93 cl_git_pass(git_tree_entry_bypath(&tentry
, tree
, "a/b"));
94 cl_git_fail(git_tree_entry_bypath(&tentry
, tree
, "a/b/c"));
95 git_tree_entry_free(tentry
);
99 void test_index_collision__add_with_highstage_1(void)
101 git_index_entry entry
;
103 memset(&entry
, 0, sizeof(entry
));
104 entry
.ctime
.seconds
= 12346789;
105 entry
.mtime
.seconds
= 12346789;
106 entry
.mode
= 0100644;
108 git_oid_cpy(&entry
.id
, &g_empty_id
);
111 GIT_INDEX_ENTRY_STAGE_SET(&entry
, 2);
112 cl_git_pass(git_index_add(g_index
, &entry
));
114 /* create a blob beneath the previous tree entry */
115 entry
.path
= "a/b/c";
117 cl_git_pass(git_index_add(g_index
, &entry
));
119 /* create another tree entry above the blob */
121 GIT_INDEX_ENTRY_STAGE_SET(&entry
, 1);
122 cl_git_pass(git_index_add(g_index
, &entry
));
125 void test_index_collision__add_with_highstage_2(void)
127 git_index_entry entry
;
129 memset(&entry
, 0, sizeof(entry
));
130 entry
.ctime
.seconds
= 12346789;
131 entry
.mtime
.seconds
= 12346789;
132 entry
.mode
= 0100644;
134 git_oid_cpy(&entry
.id
, &g_empty_id
);
136 entry
.path
= "a/b/c";
137 GIT_INDEX_ENTRY_STAGE_SET(&entry
, 1);
138 cl_git_pass(git_index_add(g_index
, &entry
));
140 /* create a blob beneath the previous tree entry */
141 entry
.path
= "a/b/c";
142 GIT_INDEX_ENTRY_STAGE_SET(&entry
, 2);
143 cl_git_pass(git_index_add(g_index
, &entry
));
145 /* create another tree entry above the blob */
147 GIT_INDEX_ENTRY_STAGE_SET(&entry
, 3);
148 cl_git_pass(git_index_add(g_index
, &entry
));