]>
git.proxmox.com Git - libgit2.git/blob - tests/worktree/reflog.c
a68e72dcfe606d31882477d8235fd66d442453c4
1 #include "clar_libgit2.h"
2 #include "worktree_helpers.h"
6 #define COMMON_REPO "testrepo"
7 #define WORKTREE_REPO "testrepo-worktree"
9 #define REFLOG "refs/heads/testrepo-worktree"
10 #define REFLOG_MESSAGE "reflog message"
12 static worktree_fixture fixture
=
13 WORKTREE_FIXTURE_INIT(COMMON_REPO
, WORKTREE_REPO
);
15 void test_worktree_reflog__initialize(void)
17 setup_fixture_worktree(&fixture
);
20 void test_worktree_reflog__cleanup(void)
22 cleanup_fixture_worktree(&fixture
);
25 void test_worktree_reflog__read_worktree_HEAD(void)
28 const git_reflog_entry
*entry
;
30 cl_git_pass(git_reflog_read(&reflog
, fixture
.worktree
, "HEAD"));
31 cl_assert_equal_i(1, git_reflog_entrycount(reflog
));
33 entry
= git_reflog_entry_byindex(reflog
, 0);
34 cl_assert(entry
!= NULL
);
35 cl_assert_equal_s("checkout: moving from 099fabac3a9ea935598528c27f866e34089c2eff to testrepo-worktree", git_reflog_entry_message(entry
));
37 git_reflog_free(reflog
);
40 void test_worktree_reflog__read_parent_HEAD(void)
44 cl_git_pass(git_reflog_read(&reflog
, fixture
.repo
, "HEAD"));
45 /* there is no logs/HEAD in the parent repo */
46 cl_assert_equal_i(0, git_reflog_entrycount(reflog
));
48 git_reflog_free(reflog
);
51 void test_worktree_reflog__read(void)
54 const git_reflog_entry
*entry
;
56 cl_git_pass(git_reflog_read(&reflog
, fixture
.worktree
, REFLOG
));
57 cl_assert_equal_i(git_reflog_entrycount(reflog
), 1);
59 entry
= git_reflog_entry_byindex(reflog
, 0);
60 cl_assert(entry
!= NULL
);
61 cl_assert_equal_s(git_reflog_entry_message(entry
), "branch: Created from HEAD");
63 git_reflog_free(reflog
);
66 void test_worktree_reflog__append_then_read(void)
68 git_reflog
*reflog
, *parent_reflog
;
69 const git_reflog_entry
*entry
;
74 cl_git_pass(git_repository_head(&head
, fixture
.worktree
));
75 cl_assert((oid
= git_reference_target(head
)) != NULL
);
76 cl_git_pass(git_signature_now(&sig
, "foo", "foo@bar"));
78 cl_git_pass(git_reflog_read(&reflog
, fixture
.worktree
, REFLOG
));
79 cl_git_pass(git_reflog_append(reflog
, oid
, sig
, REFLOG_MESSAGE
));
80 git_reflog_write(reflog
);
82 cl_git_pass(git_reflog_read(&parent_reflog
, fixture
.repo
, REFLOG
));
83 entry
= git_reflog_entry_byindex(parent_reflog
, 0);
84 cl_assert(git_oid_cmp(oid
, &entry
->oid_old
) == 0);
85 cl_assert(git_oid_cmp(oid
, &entry
->oid_cur
) == 0);
87 git_reference_free(head
);
88 git_signature_free(sig
);
89 git_reflog_free(reflog
);
90 git_reflog_free(parent_reflog
);