summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-11-22 18:51:06 +0100
committernulltoken <emeric.fermas@gmail.com>2012-11-22 18:51:06 +0100
commit5cec896a3b7b85190a7862fb09f8ba20b2241f76 (patch)
treec374bc72694e87bf9c88a127daae1d6b1aaa9604 /tests-clar
parenta94002a983fb02eafb09788e003a545a2d23ab76 (diff)
downloadlibgit2-5cec896a3b7b85190a7862fb09f8ba20b2241f76.tar.gz
repo: Make git_repository_head_tree() return error codes
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/repo/headtree.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests-clar/repo/headtree.c b/tests-clar/repo/headtree.c
new file mode 100644
index 000000000..0e7fe93e5
--- /dev/null
+++ b/tests-clar/repo/headtree.c
@@ -0,0 +1,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_orphaned_returns_EORPHANEDHEAD(void)
+{
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(true, git_repository_head_orphan(repo));
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, 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));
+}