Commit 8be49681a68ab77d87b9d90b715314caa455ea7b

Edward Thomson 2016-06-01T22:31:16

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.

diff --git a/tests/index/read_index.c b/tests/index/read_index.c
index 30adc03..6d14bc9 100644
--- a/tests/index/read_index.c
+++ b/tests/index/read_index.c
@@ -103,3 +103,26 @@ void test_index_read_index__produces_treesame_indexes(void)
 	roundtrip_with_read_index("fd093bff70906175335656e6ce6ae05783708765");
 	roundtrip_with_read_index("ae90f12eea699729ed24555e40b9fd669da12a12");
 }
+
+void test_index_read_index__read_and_writes(void)
+{
+	git_oid tree_id, new_tree_id;
+	git_tree *tree;
+	git_index *tree_index, *new_index;
+
+	cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12"));
+	cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
+	cl_git_pass(git_index_new(&tree_index));
+	cl_git_pass(git_index_read_tree(tree_index, tree));
+	cl_git_pass(git_index_read_index(_index, tree_index));
+	cl_git_pass(git_index_write(_index));
+
+	cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
+	cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
+
+	cl_assert_equal_oid(&tree_id, &new_tree_id);
+
+	git_tree_free(tree);
+	git_index_free(tree_index);
+	git_index_free(new_index);
+}