|
| 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 | + |
| 12 | +static worktree_fixture fixture = |
| 13 | + WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO); |
| 14 | + |
| 15 | +void test_worktree_reflog__initialize(void) |
| 16 | +{ |
| 17 | + setup_fixture_worktree(&fixture); |
| 18 | +} |
| 19 | + |
| 20 | +void test_worktree_reflog__cleanup(void) |
| 21 | +{ |
| 22 | + cleanup_fixture_worktree(&fixture); |
| 23 | +} |
| 24 | + |
| 25 | +void test_worktree_reflog__read(void) |
| 26 | +{ |
| 27 | + git_reflog *reflog; |
| 28 | + const git_reflog_entry *entry; |
| 29 | + |
| 30 | + cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG)); |
| 31 | + cl_assert_equal_i(git_reflog_entrycount(reflog), 1); |
| 32 | + |
| 33 | + entry = git_reflog_entry_byindex(reflog, 0); |
| 34 | + cl_assert(entry != NULL); |
| 35 | + cl_assert_equal_s(git_reflog_entry_message(entry), "branch: Created from HEAD"); |
| 36 | + |
| 37 | + git_reflog_free(reflog); |
| 38 | +} |
| 39 | + |
| 40 | +void test_worktree_reflog__append_then_read(void) |
| 41 | +{ |
| 42 | + git_reflog *reflog, *parent_reflog; |
| 43 | + const git_reflog_entry *entry; |
| 44 | + git_reference *head; |
| 45 | + git_signature *sig; |
| 46 | + const git_oid *oid; |
| 47 | + |
| 48 | + cl_git_pass(git_repository_head(&head, fixture.worktree)); |
| 49 | + cl_assert((oid = git_reference_target(head)) != NULL); |
| 50 | + cl_git_pass(git_signature_now(&sig, "foo", "foo@bar")); |
| 51 | + |
| 52 | + cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG)); |
| 53 | + cl_git_pass(git_reflog_append(reflog, oid, sig, REFLOG_MESSAGE)); |
| 54 | + git_reflog_write(reflog); |
| 55 | + |
| 56 | + cl_git_pass(git_reflog_read(&parent_reflog, fixture.repo, REFLOG)); |
| 57 | + entry = git_reflog_entry_byindex(parent_reflog, 0); |
| 58 | + cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0); |
| 59 | + cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0); |
| 60 | + |
| 61 | + git_reference_free(head); |
| 62 | + git_signature_free(sig); |
| 63 | + git_reflog_free(reflog); |
| 64 | + git_reflog_free(parent_reflog); |
| 65 | +} |
0 commit comments