summaryrefslogtreecommitdiff
path: root/tests-clar/notes/notes.c
diff options
context:
space:
mode:
authorschu <schu-github@schulog.org>2012-02-15 00:33:38 +0100
committerschu <schu-github@schulog.org>2012-02-15 20:32:14 +0100
commitbf477ed4a86d4183f7e38e4667a1f623270bf5d2 (patch)
treea3a4752971f2f8e031e78c78e48f5d142e7210ea /tests-clar/notes/notes.c
parent905919e63b7b4357ca75ef5e8bfeca7485428dc9 (diff)
downloadlibgit2-bf477ed4a86d4183f7e38e4667a1f623270bf5d2.tar.gz
Add git notes API
This commit adds basic git notes support to libgit2, namely: * git_note_read * git_note_message * git_note_oid * git_note_create * git_note_remove In the long run, we probably want to provide some convenience callback mechanism for merging and moving (filter-branch) notes. Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'tests-clar/notes/notes.c')
-rw-r--r--tests-clar/notes/notes.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c
new file mode 100644
index 000000000..eeb25eca0
--- /dev/null
+++ b/tests-clar/notes/notes.c
@@ -0,0 +1,49 @@
+#include "clar_libgit2.h"
+
+static git_repository *_repo;
+static git_note *_note;
+static git_blob *_blob;
+static git_signature *_sig;
+
+void test_notes_notes__initialize(void)
+{
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
+}
+
+void test_notes_notes__cleanup(void)
+{
+ git_note_free(_note);
+ git_blob_free(_blob);
+ git_signature_free(_sig);
+
+ git_repository_free(_repo);
+ cl_fixture_cleanup("testrepo.git");
+}
+
+void test_notes_notes__1(void)
+{
+ git_oid oid, note_oid;
+
+ cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
+
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
+
+ cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
+
+ cl_assert(!strcmp(git_note_message(_note), "hello world\n"));
+ cl_assert(!git_oid_cmp(git_note_oid(_note), &note_oid));
+
+ cl_git_pass(git_blob_lookup(&_blob, _repo, &note_oid));
+ cl_assert(!strcmp(git_note_message(_note), git_blob_rawcontent(_blob)));
+
+ cl_git_fail(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
+ cl_git_fail(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
+
+ cl_git_pass(git_note_remove(_repo, NULL, _sig, _sig, &oid));
+ cl_git_pass(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
+
+ cl_git_fail(git_note_remove(_repo, NULL, _sig, _sig, &note_oid));
+ cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
+}