]> git.proxmox.com Git - libgit2.git/blame - tests/worktree/reflog.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / worktree / reflog.c
CommitLineData
e9403024
PS
1#include "clar_libgit2.h"
2#include "worktree_helpers.h"
3
4#include "reflog.h"
5
6#define COMMON_REPO "testrepo"
7#define WORKTREE_REPO "testrepo-worktree"
8
9#define REFLOG "refs/heads/testrepo-worktree"
10#define REFLOG_MESSAGE "reflog message"
11
12static worktree_fixture fixture =
13 WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
14
15void test_worktree_reflog__initialize(void)
16{
17 setup_fixture_worktree(&fixture);
18}
19
20void test_worktree_reflog__cleanup(void)
21{
22 cleanup_fixture_worktree(&fixture);
23}
24
4b3ec53c
XL
25void test_worktree_reflog__read_worktree_HEAD(void)
26{
27 git_reflog *reflog;
28 const git_reflog_entry *entry;
29
30 cl_git_pass(git_reflog_read(&reflog, fixture.worktree, "HEAD"));
31 cl_assert_equal_i(1, git_reflog_entrycount(reflog));
32
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));
36
37 git_reflog_free(reflog);
38}
39
40void test_worktree_reflog__read_parent_HEAD(void)
41{
42 git_reflog *reflog;
43
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));
47
48 git_reflog_free(reflog);
49}
50
e9403024
PS
51void test_worktree_reflog__read(void)
52{
53 git_reflog *reflog;
54 const git_reflog_entry *entry;
55
56 cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
57 cl_assert_equal_i(git_reflog_entrycount(reflog), 1);
58
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");
62
63 git_reflog_free(reflog);
64}
65
66void test_worktree_reflog__append_then_read(void)
67{
68 git_reflog *reflog, *parent_reflog;
69 const git_reflog_entry *entry;
70 git_reference *head;
71 git_signature *sig;
72 const git_oid *oid;
73
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"));
77
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);
81
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);
86
87 git_reference_free(head);
88 git_signature_free(sig);
89 git_reflog_free(reflog);
90 git_reflog_free(parent_reflog);
91}