summaryrefslogtreecommitdiff
path: root/tests/worktree
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2015-10-27 12:37:51 +0100
committerPatrick Steinhardt <ps@pks.im>2017-02-13 11:03:01 +0100
commit04fb12abb24810391fa19af5696eb38629d650df (patch)
treecd926fbf2e9e3172ea9d0618efe6505e06089657 /tests/worktree
parentf0cfc34105fd68af9eb6e2024459c40c45e7d3a0 (diff)
downloadlibgit2-04fb12abb24810391fa19af5696eb38629d650df.tar.gz
worktree: implement functions reading HEAD
Implement `git_repository_head_for_worktree` and `git_repository_head_detached_for_worktree` for directly accessing a worktree's HEAD without opening it as a `git_repository` first.
Diffstat (limited to 'tests/worktree')
-rw-r--r--tests/worktree/repository.c63
-rw-r--r--tests/worktree/worktree.c1
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/worktree/repository.c b/tests/worktree/repository.c
new file mode 100644
index 000000000..5c7595c64
--- /dev/null
+++ b/tests/worktree/repository.c
@@ -0,0 +1,63 @@
+#include "clar_libgit2.h"
+#include "worktree_helpers.h"
+#include "submodule/submodule_helpers.h"
+
+#include "repository.h"
+
+#define COMMON_REPO "testrepo"
+#define WORKTREE_REPO "testrepo-worktree"
+
+static worktree_fixture fixture =
+ WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
+
+void test_worktree_repository__initialize(void)
+{
+ setup_fixture_worktree(&fixture);
+}
+
+void test_worktree_repository__cleanup(void)
+{
+ cleanup_fixture_worktree(&fixture);
+}
+
+void test_worktree_repository__head(void)
+{
+ git_reference *ref, *head;
+
+ cl_git_pass(git_reference_lookup(&ref, fixture.repo, "refs/heads/testrepo-worktree"));
+ cl_git_pass(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
+ cl_assert(git_reference_cmp(ref, head) == 0);
+
+ git_reference_free(ref);
+ git_reference_free(head);
+}
+
+void test_worktree_repository__head_fails_for_invalid_worktree(void)
+{
+ git_reference *head = NULL;
+
+ cl_git_fail(git_repository_head_for_worktree(&head, fixture.repo, "invalid"));
+ cl_assert(head == NULL);
+}
+
+void test_worktree_repository__head_detached(void)
+{
+ git_reference *ref, *head;
+
+ cl_git_pass(git_reference_lookup(&ref, fixture.repo, "refs/heads/testrepo-worktree"));
+ cl_git_pass(git_repository_set_head_detached(fixture.worktree, &ref->target.oid));
+
+ cl_assert(git_repository_head_detached(fixture.worktree));
+ cl_assert(git_repository_head_detached_for_worktree(fixture.repo, "testrepo-worktree"));
+ cl_git_fail(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
+
+ git_reference_free(ref);
+}
+
+void test_worktree_repository__head_detached_fails_for_invalid_worktree(void)
+{
+ git_reference *head = NULL;
+
+ cl_git_fail(git_repository_head_detached_for_worktree(fixture.repo, "invalid"));
+ cl_assert(head == NULL);
+}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 7758b1b1c..756cf387b 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "worktree_helpers.h"
+#include "checkout.h"
#include "repository.h"
#include "worktree.h"