mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 11:18:16 +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.
69 lines
1.9 KiB
C
69 lines
1.9 KiB
C
#include "clay_libgit2.h"
|
|
|
|
void test_repo_getters__initialize(void)
|
|
{
|
|
cl_fixture_sandbox("testrepo.git");
|
|
}
|
|
|
|
void test_repo_getters__cleanup(void)
|
|
{
|
|
cl_fixture_cleanup("testrepo.git");
|
|
}
|
|
|
|
void test_repo_getters__empty(void)
|
|
{
|
|
git_repository *repo_empty, *repo_normal;
|
|
|
|
cl_git_pass(git_repository_open(&repo_normal, cl_fixture("testrepo.git")));
|
|
cl_assert(git_repository_is_empty(repo_normal) == 0);
|
|
git_repository_free(repo_normal);
|
|
|
|
cl_git_pass(git_repository_open(&repo_empty, cl_fixture("empty_bare.git")));
|
|
cl_assert(git_repository_is_empty(repo_empty) == 1);
|
|
git_repository_free(repo_empty);
|
|
}
|
|
|
|
void test_repo_getters__head_detached(void)
|
|
{
|
|
git_repository *repo;
|
|
git_reference *ref;
|
|
git_oid oid;
|
|
|
|
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
|
|
|
|
cl_assert(git_repository_head_detached(repo) == 0);
|
|
|
|
/* detach the HEAD */
|
|
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
|
|
cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
|
|
cl_assert(git_repository_head_detached(repo) == 1);
|
|
|
|
/* take the reop back to it's original state */
|
|
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
|
|
cl_assert(git_repository_head_detached(repo) == 0);
|
|
|
|
git_reference_free(ref);
|
|
git_repository_free(repo);
|
|
}
|
|
|
|
void test_repo_getters__head_orphan(void)
|
|
{
|
|
git_repository *repo;
|
|
git_reference *ref;
|
|
|
|
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
|
|
|
|
cl_assert(git_repository_head_orphan(repo) == 0);
|
|
|
|
/* orphan HEAD */
|
|
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1));
|
|
cl_assert(git_repository_head_orphan(repo) == 1);
|
|
|
|
/* take the reop back to it's original state */
|
|
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
|
|
cl_assert(git_repository_head_orphan(repo) == 0);
|
|
|
|
git_reference_free(ref);
|
|
git_repository_free(repo);
|
|
}
|