mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-10 03:56:58 +00:00

The ownership semantics have been changed all over the library to be consistent. There are no more "borrowed" or duplicated references. Main changes: - `git_repository_open2` and `3` have been dropped. - Added setters and getters to hotswap all the repository owned objects: `git_repository_index` `git_repository_set_index` `git_repository_odb` `git_repository_set_odb` `git_repository_config` `git_repository_set_config` `git_repository_workdir` `git_repository_set_workdir` Now working directories/index files/ODBs and so on can be hot-swapped after creating a repository and between operations. - All these objects now have proper ownership semantics with refcounting: they all require freeing after they are no longer needed (the repository always keeps its internal reference). - Repository open and initialization has been updated to keep in mind the configuration files. Bare repositories are now always detected, and a default config file is created on init. - All the tests affected by these changes have been dropped from the old test suite and ported to the new one.
76 lines
2.7 KiB
C
76 lines
2.7 KiB
C
#include "clay_libgit2.h"
|
|
|
|
static git_repository *repo;
|
|
const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
|
|
static git_tree *tree;
|
|
|
|
void test_object_tree_frompath__initialize(void)
|
|
{
|
|
git_oid id;
|
|
|
|
cl_fixture_sandbox("testrepo.git");
|
|
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
|
|
cl_assert(repo != NULL);
|
|
|
|
cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid));
|
|
cl_git_pass(git_tree_lookup(&tree, repo, &id));
|
|
cl_assert(tree != NULL);
|
|
}
|
|
|
|
void test_object_tree_frompath__cleanup(void)
|
|
{
|
|
git_tree_close(tree);
|
|
git_repository_free(repo);
|
|
cl_fixture_cleanup("testrepo.git");
|
|
}
|
|
|
|
static void assert_tree_from_path(git_tree *root, const char *path, git_error expected_result, const char *expected_raw_oid)
|
|
{
|
|
git_tree *containing_tree = NULL;
|
|
|
|
cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result);
|
|
|
|
if (containing_tree == NULL && expected_result != GIT_SUCCESS)
|
|
return;
|
|
|
|
cl_assert(containing_tree != NULL && expected_result == GIT_SUCCESS);
|
|
|
|
cl_assert(git_oid_streq(git_object_id((const git_object *)containing_tree), expected_raw_oid) == GIT_SUCCESS);
|
|
|
|
git_tree_close(containing_tree);
|
|
}
|
|
|
|
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
|
|
{
|
|
/* Will return self if given a one path segment... */
|
|
assert_tree_from_path(tree, "README", GIT_SUCCESS, tree_with_subtrees_oid);
|
|
|
|
/* ...even one that lead to a non existent tree entry. */
|
|
assert_tree_from_path(tree, "i-do-not-exist.txt", GIT_SUCCESS, tree_with_subtrees_oid);
|
|
|
|
/* Will return fgh tree oid given this following path... */
|
|
assert_tree_from_path(tree, "ab/de/fgh/1.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
|
|
|
|
/* ... and ab tree oid given this one. */
|
|
assert_tree_from_path(tree, "ab/de", GIT_SUCCESS, "f1425cef211cc08caa31e7b545ffb232acb098c3");
|
|
|
|
/* Will succeed if given a valid path which leads to a tree entry which doesn't exist */
|
|
assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
|
|
}
|
|
|
|
void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void)
|
|
{
|
|
assert_tree_from_path(tree, "nope/de/fgh/1.txt", GIT_ENOTFOUND, NULL);
|
|
assert_tree_from_path(tree, "ab/me-neither/fgh/2.txt", GIT_ENOTFOUND, NULL);
|
|
}
|
|
|
|
void test_object_tree_frompath__fail_when_processing_an_invalid_path(void)
|
|
{
|
|
assert_tree_from_path(tree, "/", GIT_EINVALIDPATH, NULL);
|
|
assert_tree_from_path(tree, "/ab", GIT_EINVALIDPATH, NULL);
|
|
assert_tree_from_path(tree, "/ab/de", GIT_EINVALIDPATH, NULL);
|
|
assert_tree_from_path(tree, "ab/", GIT_EINVALIDPATH, NULL);
|
|
assert_tree_from_path(tree, "ab//de", GIT_EINVALIDPATH, NULL);
|
|
assert_tree_from_path(tree, "ab/de/", GIT_EINVALIDPATH, NULL);
|
|
}
|