]> git.proxmox.com Git - libgit2.git/blame - tests/worktree/repository.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / worktree / repository.c
CommitLineData
04fb12ab
PS
1#include "clar_libgit2.h"
2#include "worktree_helpers.h"
3#include "submodule/submodule_helpers.h"
4
5#include "repository.h"
6
7#define COMMON_REPO "testrepo"
8#define WORKTREE_REPO "testrepo-worktree"
9
10static worktree_fixture fixture =
11 WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
12
13void test_worktree_repository__initialize(void)
14{
15 setup_fixture_worktree(&fixture);
16}
17
18void test_worktree_repository__cleanup(void)
19{
20 cleanup_fixture_worktree(&fixture);
21}
22
23void test_worktree_repository__head(void)
24{
25 git_reference *ref, *head;
26
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);
4b3ec53c 30 cl_assert(git_reference_owner(ref) == fixture.repo);
04fb12ab
PS
31
32 git_reference_free(ref);
33 git_reference_free(head);
34}
35
36void test_worktree_repository__head_fails_for_invalid_worktree(void)
37{
38 git_reference *head = NULL;
39
40 cl_git_fail(git_repository_head_for_worktree(&head, fixture.repo, "invalid"));
41 cl_assert(head == NULL);
42}
43
44void test_worktree_repository__head_detached(void)
45{
46 git_reference *ref, *head;
47
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));
50
51 cl_assert(git_repository_head_detached(fixture.worktree));
52 cl_assert(git_repository_head_detached_for_worktree(fixture.repo, "testrepo-worktree"));
22a2d3d5
UG
53 cl_git_pass(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
54
55 cl_assert_equal_oid(&ref->target.oid, &head->target.oid);
04fb12ab
PS
56
57 git_reference_free(ref);
22a2d3d5 58 git_reference_free(head);
04fb12ab
PS
59}
60
61void test_worktree_repository__head_detached_fails_for_invalid_worktree(void)
62{
63 git_reference *head = NULL;
64
65 cl_git_fail(git_repository_head_detached_for_worktree(fixture.repo, "invalid"));
66 cl_assert(head == NULL);
67}