listall.c 1.16 KB
Newer Older
1 2 3 4 5 6 7 8
#include "clar_libgit2.h"
#include "posix.h"

static git_repository *repo;
static git_strarray ref_list;

static void ensure_no_refname_starts_with_a_forward_slash(const char *path)
{
9
	size_t i;
10 11

	cl_git_pass(git_repository_open(&repo, path));
12
	cl_git_pass(git_reference_list(&ref_list, repo));
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

	cl_assert(ref_list.count > 0);

	for (i = 0; i < ref_list.count; i++)
		cl_assert(git__prefixcmp(ref_list.strings[i], "/") != 0);

	git_strarray_free(&ref_list);
	git_repository_free(repo);
}

void test_refs_listall__from_repository_opened_through_workdir_path(void)
{
	cl_fixture_sandbox("status");
	cl_git_pass(p_rename("status/.gitted", "status/.git"));

	ensure_no_refname_starts_with_a_forward_slash("status");

	cl_fixture_cleanup("status");
}

void test_refs_listall__from_repository_opened_through_gitdir_path(void)
{
	ensure_no_refname_starts_with_a_forward_slash(cl_fixture("testrepo.git"));
}
37 38 39 40

void test_refs_listall__from_repository_with_no_trailing_newline(void)
{
	cl_git_pass(git_repository_open(&repo, cl_fixture("bad_tag.git")));
41
	cl_git_pass(git_reference_list(&ref_list, repo));
42 43 44 45 46 47

	cl_assert(ref_list.count > 0);

	git_strarray_free(&ref_list);
	git_repository_free(repo);
}