diff options
author | Edward Thomson <ethomson@github.com> | 2016-06-01 14:52:25 -0500 |
---|---|---|
committer | Carlos MartÃn Nieto <cmn@dwim.me> | 2016-10-01 17:40:36 +0200 |
commit | 6c133a75755e14ae014fc75c99fa7a0848d5606e (patch) | |
tree | 224e548c52036f55668e63dffa74ac39500a4c42 | |
parent | feea2849f980035dabdcdc1dc82f5de342821632 (diff) | |
download | libgit2-6c133a75755e14ae014fc75c99fa7a0848d5606e.tar.gz |
round-trip trees through index_read_index
Read a tree into an index using `git_index_read_index` (by reading
a tree into a new index, then reading that index into the current
index), then write the index back out, ensuring that our new index
is treesame to the tree that we read.
-rw-r--r-- | tests/index/read_index.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/index/read_index.c b/tests/index/read_index.c index 82a771d54..30adc0388 100644 --- a/tests/index/read_index.c +++ b/tests/index/read_index.c @@ -71,3 +71,35 @@ void test_index_read_index__maintains_stat_cache(void) } } } + +static bool roundtrip_with_read_index(const char *tree_idstr) +{ + git_oid tree_id, new_tree_id; + git_tree *tree; + git_index *tree_index; + + cl_git_pass(git_oid_fromstr(&tree_id, tree_idstr)); + 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_tree(&new_tree_id, _index)); + + git_tree_free(tree); + git_index_free(tree_index); + + return git_oid_equal(&tree_id, &new_tree_id); +} + +void test_index_read_index__produces_treesame_indexes(void) +{ + roundtrip_with_read_index("53fc32d17276939fc79ed05badaef2db09990016"); + roundtrip_with_read_index("944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); + roundtrip_with_read_index("1810dff58d8a660512d4832e740f692884338ccd"); + roundtrip_with_read_index("d52a8fe84ceedf260afe4f0287bbfca04a117e83"); + roundtrip_with_read_index("c36d8ea75da8cb510fcb0c408c1d7e53f9a99dbe"); + roundtrip_with_read_index("7b2417a23b63e1fdde88c80e14b33247c6e5785a"); + roundtrip_with_read_index("f82a8eb4cb20e88d1030fd10d89286215a715396"); + roundtrip_with_read_index("fd093bff70906175335656e6ce6ae05783708765"); + roundtrip_with_read_index("ae90f12eea699729ed24555e40b9fd669da12a12"); +} |