void test_notes_notesref__config_corenotesref(void) { git_oid oid, note_oid; const char *default_ref; cl_git_pass(git_signature_now(&_sig, "alice", "*****@*****.**")); 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")); cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "test123test\n")); cl_git_pass(git_note_read(&_note, _repo, NULL, &oid)); cl_assert(!strcmp(git_note_message(_note), "test123test\n")); cl_assert(!git_oid_cmp(git_note_oid(_note), ¬e_oid)); git_note_free(_note); cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid)); cl_assert(!strcmp(git_note_message(_note), "test123test\n")); cl_assert(!git_oid_cmp(git_note_oid(_note), ¬e_oid)); cl_git_pass(git_note_default_ref(&default_ref, _repo)); cl_assert(!strcmp(default_ref, "refs/notes/mydefaultnotesref")); cl_git_pass(git_config_delete(_cfg, "core.notesRef")); cl_git_pass(git_note_default_ref(&default_ref, _repo)); cl_assert(!strcmp(default_ref, GIT_NOTES_DEFAULT_REF)); }
/** * Default notes reference * * Get the default notes reference for a repository * @param repo S4 class git_repository * @return Character vector of length one with name of default * reference */ SEXP git2r_note_default_ref(SEXP repo) { int err; SEXP result = R_NilValue; const char *ref; git_repository *repository = NULL; repository = git2r_repository_open(repo); if (!repository) git2r_error(git2r_err_invalid_repository, __func__, NULL); err = git_note_default_ref(&ref, repository); if (GIT_OK != err) goto cleanup; PROTECT(result = allocVector(STRSXP, 1)); SET_STRING_ELT(result, 0, mkChar(ref)); cleanup: if (repository) git_repository_free(repository); if (R_NilValue != result) UNPROTECT(1); if (GIT_OK != err) git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message); return result; }
/** * List all the notes within a specified namespace. * * @param repo S4 class git_repository * @param ref Optional reference to read from. * @return VECXSP with S4 objects of class git_note */ SEXP git2r_notes(SEXP repo, SEXP ref) { int err; SEXP result = R_NilValue; const char *notes_ref = NULL; git2r_note_foreach_cb_data cb_data = {0, R_NilValue, R_NilValue, NULL, NULL}; git_repository *repository = NULL; if (R_NilValue != ref) { if (git2r_arg_check_string(ref)) git2r_error(git2r_err_string_arg, __func__, "ref"); notes_ref = CHAR(STRING_ELT(ref, 0)); } repository = git2r_repository_open(repo); if (!repository) git2r_error(git2r_err_invalid_repository, __func__, NULL); if (NULL == notes_ref) { err = git_note_default_ref(¬es_ref, repository); if (GIT_OK != err) goto cleanup; } /* Count number of notes before creating the list */ err = git_note_foreach(repository, notes_ref, &git2r_note_foreach_cb, &cb_data); if (GIT_OK != err) { if (GIT_ENOTFOUND == err) { err = GIT_OK; PROTECT(result = allocVector(VECSXP, 0)); } goto cleanup; } PROTECT(result = allocVector(VECSXP, cb_data.n)); cb_data.n = 0; cb_data.list = result; cb_data.repo = repo; cb_data.repository = repository; cb_data.notes_ref = notes_ref; err = git_note_foreach(repository, notes_ref, &git2r_note_foreach_cb, &cb_data); cleanup: if (repository) git_repository_free(repository); if (R_NilValue != result) UNPROTECT(1); if (GIT_OK != err) git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message); return result; }
/* * call-seq: * repo.notes_default_ref() -> string * * Get the default notes reference for a +repository+: * * Returns a new String object. * * repo.default_notes_ref #=> "refs/notes/commits" */ static VALUE rb_git_note_default_ref_GET(VALUE self) { git_repository *repo = NULL; const char * ref_name; Data_Get_Struct(self, git_repository, repo); rugged_exception_check( git_note_default_ref(&ref_name, repo) ); return rb_str_new_utf8(ref_name); }
void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void) { git_oid note_oid, target_oid; git_note *note, *default_namespace_note; const char *default_ref; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); cl_git_pass(git_note_default_ref(&default_ref, _repo)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid)); assert_note_equal(note, "hello world\n", ¬e_oid); assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid); git_note_free(note); git_note_free(default_namespace_note); }