Skip to content

Commit 1d41b86

Browse files
committed
tree: add a failing test for unsorted input
We do not currently use the sorted version of this input in the function, which means we produce bad results.
1 parent e1c1433 commit 1d41b86

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/object/tree/update.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,63 @@ void test_object_tree_update__add_blobs(void)
196196
git_tree_free(base_tree);
197197
}
198198

199+
void test_object_tree_update__add_blobs_unsorted(void)
200+
{
201+
git_oid tree_index_id, tree_updater_id, base_id;
202+
git_tree *base_tree;
203+
git_index *idx;
204+
git_index_entry entry = { {0} };
205+
int i;
206+
const char *paths[] = {
207+
"some/deep/path",
208+
"a/path/elsewhere",
209+
"some/other/path",
210+
};
211+
212+
git_tree_update updates[] = {
213+
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[0]},
214+
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[1]},
215+
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[2]},
216+
};
217+
218+
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
219+
220+
entry.mode = GIT_FILEMODE_BLOB;
221+
cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92"));
222+
223+
for (i = 0; i < 3; i++) {
224+
cl_git_pass(git_oid_fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92"));
225+
}
226+
227+
for (i = 0; i < 2; i++) {
228+
int j;
229+
230+
/* Create it with an index */
231+
cl_git_pass(git_index_new(&idx));
232+
233+
base_tree = NULL;
234+
if (i == 1) {
235+
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
236+
cl_git_pass(git_index_read_tree(idx, base_tree));
237+
}
238+
239+
for (j = 0; j < 3; j++) {
240+
entry.path = paths[j];
241+
cl_git_pass(git_index_add(idx, &entry));
242+
}
243+
244+
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
245+
git_index_free(idx);
246+
247+
/* Perform the same operations via the tree updater */
248+
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 3, updates));
249+
250+
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
251+
}
252+
253+
git_tree_free(base_tree);
254+
}
255+
199256
void test_object_tree_update__add_conflict(void)
200257
{
201258
int i;

0 commit comments

Comments
 (0)