]>
git.proxmox.com Git - libgit2.git/blob - tests/libgit2/worktree/repository.c
1 #include "clar_libgit2.h"
2 #include "worktree_helpers.h"
3 #include "submodule/submodule_helpers.h"
5 #include "repository.h"
7 #define COMMON_REPO "testrepo"
8 #define WORKTREE_REPO "testrepo-worktree"
10 static worktree_fixture fixture
=
11 WORKTREE_FIXTURE_INIT(COMMON_REPO
, WORKTREE_REPO
);
13 void test_worktree_repository__initialize(void)
15 setup_fixture_worktree(&fixture
);
18 void test_worktree_repository__cleanup(void)
20 cleanup_fixture_worktree(&fixture
);
23 void test_worktree_repository__head(void)
25 git_reference
*ref
, *head
;
27 cl_git_pass(git_reference_lookup(&ref
, fixture
.repo
, "refs/heads/testrepo-worktree"));
28 cl_git_pass(git_repository_head_for_worktree(&head
, fixture
.repo
, "testrepo-worktree"));
29 cl_assert(git_reference_cmp(ref
, head
) == 0);
30 cl_assert(git_reference_owner(ref
) == fixture
.repo
);
32 git_reference_free(ref
);
33 git_reference_free(head
);
36 void test_worktree_repository__head_fails_for_invalid_worktree(void)
38 git_reference
*head
= NULL
;
40 cl_git_fail(git_repository_head_for_worktree(&head
, fixture
.repo
, "invalid"));
41 cl_assert(head
== NULL
);
44 void test_worktree_repository__head_detached(void)
46 git_reference
*ref
, *head
;
48 cl_git_pass(git_reference_lookup(&ref
, fixture
.repo
, "refs/heads/testrepo-worktree"));
49 cl_git_pass(git_repository_set_head_detached(fixture
.worktree
, &ref
->target
.oid
));
51 cl_assert(git_repository_head_detached(fixture
.worktree
));
52 cl_assert(git_repository_head_detached_for_worktree(fixture
.repo
, "testrepo-worktree"));
53 cl_git_pass(git_repository_head_for_worktree(&head
, fixture
.repo
, "testrepo-worktree"));
55 cl_assert_equal_oid(&ref
->target
.oid
, &head
->target
.oid
);
57 git_reference_free(ref
);
58 git_reference_free(head
);
61 void test_worktree_repository__head_detached_fails_for_invalid_worktree(void)
63 git_reference
*head
= NULL
;
65 cl_git_fail(git_repository_head_detached_for_worktree(fixture
.repo
, "invalid"));
66 cl_assert(head
== NULL
);