]>
git.proxmox.com Git - libgit2.git/blob - tests/t09-tree.c
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
26 #include "test_helpers.h"
30 static const char *tree_oid
= "1810dff58d8a660512d4832e740f692884338ccd";
32 BEGIN_TEST(read0
, "acces randomly the entries on a loaded tree")
37 must_pass(git_repository_open(&repo
, REPOSITORY_FOLDER
));
39 git_oid_mkstr(&id
, tree_oid
);
41 must_pass(git_tree_lookup(&tree
, repo
, &id
));
43 must_be_true(git_tree_entry_byname(tree
, "README") != NULL
);
44 must_be_true(git_tree_entry_byname(tree
, "NOTEXISTS") == NULL
);
45 must_be_true(git_tree_entry_byname(tree
, "") == NULL
);
46 must_be_true(git_tree_entry_byindex(tree
, 0) != NULL
);
47 must_be_true(git_tree_entry_byindex(tree
, 2) != NULL
);
48 must_be_true(git_tree_entry_byindex(tree
, 3) == NULL
);
49 must_be_true(git_tree_entry_byindex(tree
, -1) == NULL
);
51 git_repository_free(repo
);
54 BEGIN_TEST(read1
, "read a tree from the repository")
58 git_tree_entry
*entry
;
61 must_pass(git_repository_open(&repo
, REPOSITORY_FOLDER
));
63 git_oid_mkstr(&id
, tree_oid
);
65 must_pass(git_tree_lookup(&tree
, repo
, &id
));
67 must_be_true(git_tree_entrycount(tree
) == 3);
69 /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
70 must_be_true(git_object_lookup(&obj
, repo
, &id
, GIT_OBJ_TREE
) == 0);
71 must_be_true(git_object_lookup(&obj
, repo
, &id
, GIT_OBJ_BLOB
) == GIT_EINVALIDTYPE
);
73 entry
= git_tree_entry_byname(tree
, "README");
74 must_be_true(entry
!= NULL
);
76 must_be_true(strcmp(git_tree_entry_name(entry
), "README") == 0);
78 must_pass(git_tree_entry_2object(&obj
, repo
, entry
));
80 git_repository_free(repo
);
86 // ADD_TEST(write0); /* TODO THREADSAFE */