Hash :
605da51a
Author :
Date :
2013-09-17T09:50:30
No such thing as an orphan branch Unfortunately git-core uses the term "unborn branch" and "orphan branch" interchangeably. However, "orphan" is only really there for the checkout command, which has the `--orphan` option so it doesn't actually create the branch. Branches never have parents, so the distinction of a branch with no parents is odd to begin with. Crucially, the error messages deal with unborn branches, so let's use that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "clar_libgit2.h"
#include "repository.h"
#include "repo_helpers.h"
#include "posix.h"
static git_repository *repo;
static git_tree *tree;
void test_repo_headtree__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
tree = NULL;
}
void test_repo_headtree__cleanup(void)
{
git_tree_free(tree);
cl_git_sandbox_cleanup();
}
void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void)
{
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_assert(git_oid_streq(git_tree_id(tree), "az"));
}
void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(void)
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_assert(git_oid_streq(git_tree_id(tree), "az"));
}
void test_repo_headtree__when_head_is_unborn_returns_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(true, git_repository_head_unborn(repo));
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head_tree(&tree, repo));
}
void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void)
{
delete_head(repo);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head_tree(&tree, repo));
}