Blame tests/worktree/reflog.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "worktree_helpers.h"
Packit Service 20376f
Packit Service 20376f
#include "reflog.h"
Packit Service 20376f
Packit Service 20376f
#define COMMON_REPO "testrepo"
Packit Service 20376f
#define WORKTREE_REPO "testrepo-worktree"
Packit Service 20376f
Packit Service 20376f
#define REFLOG "refs/heads/testrepo-worktree"
Packit Service 20376f
#define REFLOG_MESSAGE "reflog message"
Packit Service 20376f
Packit Service 20376f
static worktree_fixture fixture =
Packit Service 20376f
	WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
Packit Service 20376f
Packit Service 20376f
void test_worktree_reflog__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	setup_fixture_worktree(&fixture);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_worktree_reflog__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cleanup_fixture_worktree(&fixture);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_worktree_reflog__read(void)
Packit Service 20376f
{
Packit Service 20376f
	git_reflog *reflog;
Packit Service 20376f
	const git_reflog_entry *entry;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
Packit Service 20376f
	cl_assert_equal_i(git_reflog_entrycount(reflog), 1);
Packit Service 20376f
Packit Service 20376f
	entry = git_reflog_entry_byindex(reflog, 0);
Packit Service 20376f
	cl_assert(entry != NULL);
Packit Service 20376f
	cl_assert_equal_s(git_reflog_entry_message(entry), "branch: Created from HEAD");
Packit Service 20376f
Packit Service 20376f
	git_reflog_free(reflog);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_worktree_reflog__append_then_read(void)
Packit Service 20376f
{
Packit Service 20376f
	git_reflog *reflog, *parent_reflog;
Packit Service 20376f
	const git_reflog_entry *entry;
Packit Service 20376f
	git_reference *head;
Packit Service 20376f
	git_signature *sig;
Packit Service 20376f
	const git_oid *oid;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_head(&head, fixture.worktree));
Packit Service 20376f
	cl_assert((oid = git_reference_target(head)) != NULL);
Packit Service 20376f
	cl_git_pass(git_signature_now(&sig, "foo", "foo@bar"));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
Packit Service 20376f
	cl_git_pass(git_reflog_append(reflog, oid, sig, REFLOG_MESSAGE));
Packit Service 20376f
	git_reflog_write(reflog);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_reflog_read(&parent_reflog, fixture.repo, REFLOG));
Packit Service 20376f
	entry = git_reflog_entry_byindex(parent_reflog, 0);
Packit Service 20376f
	cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
Packit Service 20376f
	cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
Packit Service 20376f
Packit Service 20376f
	git_reference_free(head);
Packit Service 20376f
	git_signature_free(sig);
Packit Service 20376f
	git_reflog_free(reflog);
Packit Service 20376f
	git_reflog_free(parent_reflog);
Packit Service 20376f
}