]> git.proxmox.com Git - libgit2.git/blame - tests/index/read_tree.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / index / read_tree.c
CommitLineData
3fd1520c 1#include "clar_libgit2.h"
599f2849
CB
2#include "posix.h"
3
4/* Test that reading and writing a tree is a no-op */
5void test_index_read_tree__read_write_involution(void)
6{
7 git_repository *repo;
8 git_index *index;
9 git_oid tree_oid;
10 git_tree *tree;
11 git_oid expected;
12
13 p_mkdir("read_tree", 0700);
14
15 cl_git_pass(git_repository_init(&repo, "./read_tree", 0));
16 cl_git_pass(git_repository_index(&index, repo));
17
18 cl_assert(git_index_entrycount(index) == 0);
19
20 p_mkdir("./read_tree/abc", 0700);
21
22 /* Sort order: '-' < '/' < '_' */
1d415455
VM
23 cl_git_mkfile("./read_tree/abc-d", NULL);
24 cl_git_mkfile("./read_tree/abc/d", NULL);
25 cl_git_mkfile("./read_tree/abc_d", NULL);
599f2849 26
25743bd7
ET
27 cl_git_pass(git_index_add_bypath(index, "abc-d"));
28 cl_git_pass(git_index_add_bypath(index, "abc_d"));
29 cl_git_pass(git_index_add_bypath(index, "abc/d"));
599f2849
CB
30
31 /* write-tree */
43eeca04 32 cl_git_pass(git_index_write_tree(&expected, index));
599f2849
CB
33
34 /* read-tree */
35 git_tree_lookup(&tree, repo, &expected);
0ae81fc4 36 cl_git_pass(git_index_read_tree(index, tree));
91d46f8d 37 git_tree_free(tree);
599f2849 38
43eeca04 39 cl_git_pass(git_index_write_tree(&tree_oid, index));
0cee70eb 40 cl_assert_equal_oid(&expected, &tree_oid);
599f2849
CB
41
42 git_index_free(index);
43 git_repository_free(repo);
44
45 cl_fixture_cleanup("read_tree");
46}