summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-03-03 22:56:02 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2016-03-08 13:11:49 +0100
commit47cb42da5ad2e0af7946faf053c7ea4fd92ec6da (patch)
treede7df1005f9d9e1082ddd07182e88ea024700762 /tests
parent785d8c48ea8725691da3c50e7dae8751523d4c30 (diff)
downloadlibgit2-47cb42da5ad2e0af7946faf053c7ea4fd92ec6da.tar.gz
commit: split creating the commit and writing it outcmn/commit-to-memory
Sometimes you want to create a commit but not write it out to the objectdb immediately. For these cases, provide a new function to retrieve the buffer instead of having to go through the db.
Diffstat (limited to 'tests')
-rw-r--r--tests/commit/write.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/commit/write.c b/tests/commit/write.c
index 96b7cc321..9d1ae78fb 100644
--- a/tests/commit/write.c
+++ b/tests/commit/write.c
@@ -98,6 +98,45 @@ void test_commit_write__from_memory(void)
cl_assert_equal_s(commit_message, git_commit_message(commit));
}
+void test_commit_write__into_buf(void)
+{
+ git_oid tree_id;
+ git_signature *author, *committer;
+ git_tree *tree;
+ git_commit *parent;
+ git_oid parent_id;
+ git_buf commit = GIT_BUF_INIT;
+
+ git_oid_fromstr(&tree_id, tree_id_str);
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ /* create signatures */
+ cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60));
+ cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90));
+
+ git_oid_fromstr(&parent_id, parent_id_str);
+ cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id));
+
+ cl_git_pass(git_commit_create_buffer(&commit, g_repo, author, committer,
+ NULL, root_commit_message, tree, 1, (const git_commit **) &parent));
+
+ cl_assert_equal_s(commit.ptr,
+ "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
+parent 8496071c1b46c854b31185ea97743be6a8774479\n\
+author Vicent Marti <vicent@github.com> 987654321 +0130\n\
+committer Vicent Marti <vicent@github.com> 123456789 +0100\n\
+\n\
+This is a root commit\n\
+ This is a root commit and should be the only one in this branch\n\
+");
+
+ git_buf_free(&commit);
+ git_tree_free(tree);
+ git_commit_free(parent);
+ git_signature_free(author);
+ git_signature_free(committer);
+}
+
// create a root commit
void test_commit_write__root(void)
{