notesref.c 1.79 KB
Newer Older
1 2
#include "clar_libgit2.h"

3
#include "notes.h"
4
#include "buffer.h"
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19
static git_repository *_repo;
static git_note *_note;
static git_signature *_sig;
static git_config *_cfg;

void test_notes_notesref__initialize(void)
{
	cl_fixture_sandbox("testrepo.git");
	cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
}

void test_notes_notesref__cleanup(void)
{
	git_note_free(_note);
20 21
	_note = NULL;

22
	git_signature_free(_sig);
23 24
	_sig = NULL;

25
	git_config_free(_cfg);
26
	_cfg = NULL;
27 28

	git_repository_free(_repo);
29 30
	_repo = NULL;

31 32 33 34 35 36
	cl_fixture_cleanup("testrepo.git");
}

void test_notes_notesref__config_corenotesref(void)
{
	git_oid oid, note_oid;
37
	git_buf default_ref = GIT_BUF_INIT;
38 39 40 41 42 43 44 45

	cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
	cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));

	cl_git_pass(git_repository_config(&_cfg, _repo));

	cl_git_pass(git_config_set_string(_cfg, "core.notesRef", "refs/notes/mydefaultnotesref"));

46
	cl_git_pass(git_note_create(&note_oid, _repo, NULL, _sig, _sig, &oid, "test123test\n", 0));
47 48

	cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
49
	cl_assert_equal_s("test123test\n", git_note_message(_note));
50
	cl_assert_equal_oid(git_note_id(_note), &note_oid);
51 52 53 54

	git_note_free(_note);

	cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid));
55
	cl_assert_equal_s("test123test\n", git_note_message(_note));
56
	cl_assert_equal_oid(git_note_id(_note), &note_oid);
57 58

	cl_git_pass(git_note_default_ref(&default_ref, _repo));
59 60
	cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref.ptr);
	git_buf_clear(&default_ref);
61

Ben Straub committed
62
	cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
63 64

	cl_git_pass(git_note_default_ref(&default_ref, _repo));
65 66 67
	cl_assert_equal_s(GIT_NOTES_DEFAULT_REF, default_ref.ptr);

	git_buf_free(&default_ref);
68
}