summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-06-01 22:31:16 -0500
committerEdward Thomson <ethomson@github.com>2016-06-02 02:37:04 -0500
commit91fbf9d867877d77ec0546bd45fb649721d194f8 (patch)
tree3037baff733e8876dca62ced8d4423ea6c5d15a4
parent9167c1450e45f713448ed4c0c6cb13344f69d40a (diff)
downloadlibgit2-91fbf9d867877d77ec0546bd45fb649721d194f8.tar.gz
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.
-rw-r--r--tests/index/read_index.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/index/read_index.c b/tests/index/read_index.c
index 30adc0388..6d14bc9fd 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);
+}