notes: add git_note_default_ref() Add git_note_default_ref to allow easy retrieval of the currently set default notes reference.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/include/git2/notes.h b/include/git2/notes.h
index 1b5944f..ecb37f3 100644
--- a/include/git2/notes.h
+++ b/include/git2/notes.h
@@ -92,6 +92,16 @@ GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref,
*/
GIT_EXTERN(void) git_note_free(git_note *note);
+/**
+ * Get the default notes reference for a repository
+ *
+ * @param out Pointer to the default notes reference
+ * @param repo The Git repository
+ *
+ * @return GIT_SUCCESS or an error code
+ */
+GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/src/notes.c b/src/notes.c
index 9e6722e..e533478 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -417,6 +417,12 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
return error;
}
+int git_note_default_ref(const char **out, git_repository *repo)
+{
+ assert(repo);
+ return note_get_default_ref(out, repo);
+}
+
const char * git_note_message(git_note *note)
{
assert(note);
diff --git a/tests-clar/notes/notesref.c b/tests-clar/notes/notesref.c
index f145666..79ad0af 100644
--- a/tests-clar/notes/notesref.c
+++ b/tests-clar/notes/notesref.c
@@ -1,5 +1,7 @@
#include "clar_libgit2.h"
+#include "notes.h"
+
static git_repository *_repo;
static git_note *_note;
static git_signature *_sig;
@@ -24,6 +26,7 @@ void test_notes_notesref__cleanup(void)
void test_notes_notesref__config_corenotesref(void)
{
git_oid oid, note_oid;
+ const char *default_ref;
cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
@@ -43,4 +46,12 @@ void test_notes_notesref__config_corenotesref(void)
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));
}