Add tests for detached and orphan Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
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 54 55 56 57 58 59 60
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 3447f2b..b67d27f 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -268,6 +268,46 @@ BEGIN_TEST(empty0, "test if a repository is empty or not")
git_repository_free(repo_empty);
END_TEST
+BEGIN_TEST(detached0, "test if HEAD is detached")
+ git_repository *repo;
+ git_reference *ref;
+ git_oid oid;
+
+ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+
+ must_be_true(git_repository_is_detached(repo) == 0);
+
+ /* detach the HEAD */
+ git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ must_pass(git_reference_create_oid_f(&ref, repo, "HEAD", &oid));
+ must_be_true(git_repository_is_detached(repo) == 1);
+
+ /* take the reop back to it's original state */
+ must_pass(git_reference_create_symbolic_f(&ref, repo, "HEAD", "refs/heads/master"));
+ must_be_true(git_repository_is_detached(repo) == 0);
+
+ git_repository_free(repo);
+END_TEST
+
+BEGIN_TEST(orphan0, "test if HEAD is orphan")
+ git_repository *repo;
+ git_reference *ref;
+
+ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+
+ must_be_true(git_repository_is_orphan(repo) == 0);
+
+ /* orphan HEAD */
+ must_pass(git_reference_create_symbolic_f(&ref, repo, "HEAD", "refs/heads/orphan"));
+ must_be_true(git_repository_is_orphan(repo) == 1);
+
+ /* take the reop back to it's original state */
+ must_pass(git_reference_create_symbolic_f(&ref, repo, "HEAD", "refs/heads/master"));
+ must_be_true(git_repository_is_orphan(repo) == 0);
+
+ git_repository_free(repo);
+END_TEST
+
#define DISCOVER_FOLDER TEST_RESOURCES "/discover.git"
#define SUB_REPOSITORY_FOLDER_NAME "sub_repo"
@@ -416,6 +456,8 @@ BEGIN_SUITE(repository)
ADD_TEST(open1);
ADD_TEST(open2);
ADD_TEST(empty0);
+ ADD_TEST(detached0);
+ ADD_TEST(orphan0);
ADD_TEST(discover0);
END_SUITE