File: read_tree.c

package info (click to toggle)
libgit2 0.25.1%2Breally0.24.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 28,512 kB
  • ctags: 15,888
  • sloc: ansic: 153,520; sh: 297; python: 175; makefile: 70; php: 65
file content (46 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "clar_libgit2.h"
#include "posix.h"

/* Test that reading and writing a tree is a no-op */
void test_index_read_tree__read_write_involution(void)
{
	git_repository *repo;
	git_index *index;
	git_oid tree_oid;
	git_tree *tree;
	git_oid expected;

	p_mkdir("read_tree", 0700);

	cl_git_pass(git_repository_init(&repo, "./read_tree", 0));
	cl_git_pass(git_repository_index(&index, repo));

	cl_assert(git_index_entrycount(index) == 0);

	p_mkdir("./read_tree/abc", 0700);

	/* Sort order: '-' < '/' < '_' */
	cl_git_mkfile("./read_tree/abc-d", NULL);
	cl_git_mkfile("./read_tree/abc/d", NULL);
	cl_git_mkfile("./read_tree/abc_d", NULL);

	cl_git_pass(git_index_add_bypath(index, "abc-d"));
	cl_git_pass(git_index_add_bypath(index, "abc_d"));
	cl_git_pass(git_index_add_bypath(index, "abc/d"));

	/* write-tree */
	cl_git_pass(git_index_write_tree(&expected, index));

	/* read-tree */
	git_tree_lookup(&tree, repo, &expected);
	cl_git_pass(git_index_read_tree(index, tree));
	git_tree_free(tree);

	cl_git_pass(git_index_write_tree(&tree_oid, index));
	cl_assert_equal_oid(&expected, &tree_oid);

	git_index_free(index);
	git_repository_free(repo);

	cl_fixture_cleanup("read_tree");
}