]>
Commit | Line | Data |
---|---|---|
5cec896a | 1 | #include "clar_libgit2.h" |
2 | #include "repository.h" | |
3 | #include "repo_helpers.h" | |
4 | #include "posix.h" | |
5 | ||
6 | static git_repository *repo; | |
7 | static git_tree *tree; | |
8 | ||
9 | void test_repo_headtree__initialize(void) | |
10 | { | |
11 | repo = cl_git_sandbox_init("testrepo.git"); | |
12 | tree = NULL; | |
13 | } | |
14 | ||
15 | void test_repo_headtree__cleanup(void) | |
16 | { | |
17 | git_tree_free(tree); | |
18 | cl_git_sandbox_cleanup(); | |
19 | } | |
20 | ||
21 | void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void) | |
22 | { | |
4e498646 | 23 | cl_git_pass(git_repository_detach_head(repo)); |
5cec896a | 24 | |
25 | cl_git_pass(git_repository_head_tree(&tree, repo)); | |
26 | ||
27 | cl_assert(git_oid_streq(git_tree_id(tree), "az")); | |
28 | } | |
29 | ||
30 | void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(void) | |
31 | { | |
32 | cl_assert_equal_i(false, git_repository_head_detached(repo)); | |
33 | ||
34 | cl_git_pass(git_repository_head_tree(&tree, repo)); | |
35 | ||
36 | cl_assert(git_oid_streq(git_tree_id(tree), "az")); | |
37 | } | |
38 | ||
605da51a | 39 | void test_repo_headtree__when_head_is_unborn_returns_EUNBORNBRANCH(void) |
5cec896a | 40 | { |
605da51a | 41 | make_head_unborn(repo, NON_EXISTING_HEAD); |
5cec896a | 42 | |
605da51a | 43 | cl_assert_equal_i(true, git_repository_head_unborn(repo)); |
5cec896a | 44 | |
605da51a | 45 | cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head_tree(&tree, repo)); |
5cec896a | 46 | } |
47 | ||
48 | void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void) | |
49 | { | |
50 | delete_head(repo); | |
51 | ||
52 | cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head_tree(&tree, repo)); | |
53 | } |