getters.c 1.34 KB
Newer Older
1
#include "clar_libgit2.h"
2
#include "repo/repo_helpers.h"
3

4
void test_repo_getters__is_empty_correctly_deals_with_pristine_looking_repos(void)
5
{
6 7 8 9 10 11
	git_repository *repo;

	repo = cl_git_sandbox_init("empty_bare.git");
	cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");

	cl_assert_equal_i(true, git_repository_is_empty(repo));
12

13 14
	cl_git_sandbox_cleanup();
}
15

16 17 18 19 20 21 22 23 24
void test_repo_getters__is_empty_can_detect_used_repositories(void)
{
	git_repository *repo;

	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));

	cl_assert_equal_i(false, git_repository_is_empty(repo));

	git_repository_free(repo);
25 26
}

27 28 29 30 31 32 33 34 35 36 37 38
void test_repo_getters__is_empty_can_detect_repositories_with_defaultbranch_config_empty(void)
{
	git_repository *repo;

	create_tmp_global_config("tmp_global_path", "init.defaultBranch", "");

	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
	cl_assert_equal_i(false, git_repository_is_empty(repo));

	git_repository_free(repo);
}

39 40 41 42 43
void test_repo_getters__retrieving_the_odb_honors_the_refcount(void)
{
	git_odb *odb;
	git_repository *repo;

44
	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
45 46

	cl_git_pass(git_repository_odb(&odb, repo));
47
	cl_assert(((git_refcount *)odb)->refcount.val == 2);
48 49

	git_repository_free(repo);
50
	cl_assert(((git_refcount *)odb)->refcount.val == 1);
51 52 53

	git_odb_free(odb);
}