Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91fbf9d

Browse files
author
Edward Thomson
committed
test: ensure we can round-trip a written tree
Read a tree into an index, write the index, then re-open the index and ensure that we are treesame to the original.
1 parent 9167c14 commit 91fbf9d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/index/read_index.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,26 @@ void test_index_read_index__produces_treesame_indexes(void)
103103
roundtrip_with_read_index("fd093bff70906175335656e6ce6ae05783708765");
104104
roundtrip_with_read_index("ae90f12eea699729ed24555e40b9fd669da12a12");
105105
}
106+
107+
void test_index_read_index__read_and_writes(void)
108+
{
109+
git_oid tree_id, new_tree_id;
110+
git_tree *tree;
111+
git_index *tree_index, *new_index;
112+
113+
cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12"));
114+
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
115+
cl_git_pass(git_index_new(&tree_index));
116+
cl_git_pass(git_index_read_tree(tree_index, tree));
117+
cl_git_pass(git_index_read_index(_index, tree_index));
118+
cl_git_pass(git_index_write(_index));
119+
120+
cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
121+
cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
122+
123+
cl_assert_equal_oid(&tree_id, &new_tree_id);
124+
125+
git_tree_free(tree);
126+
git_index_free(tree_index);
127+
git_index_free(new_index);
128+
}

0 commit comments

Comments
 (0)