Commit 579d87c5 by Russell Belfer

New test that inits repo and make commit

parent ce23330f
...@@ -530,3 +530,52 @@ void test_repo_init__can_reinit_an_initialized_repository(void) ...@@ -530,3 +530,52 @@ void test_repo_init__can_reinit_an_initialized_repository(void)
git_repository_free(reinit); git_repository_free(reinit);
} }
void test_repo_init__init_with_initial_commit(void)
{
git_index *index;
cl_set_cleanup(&cleanup_repository, "committed");
/* Initialize the repository */
cl_git_pass(git_repository_init(&_repo, "committed", 0));
/* Init will be automatically created when requested for a new repo */
cl_git_pass(git_repository_index(&index, _repo));
/* Create a file so we can commit it
*
* If you are writing code outside the test suite, you can create this
* file any way that you like, such as:
* FILE *fp = fopen("committed/file.txt", "w");
* fputs("some stuff\n", fp);
* fclose(fp);
* We like to use the help functions because they do error detection
* in a way that's easily compatible with our test suite.
*/
cl_git_mkfile("committed/file.txt", "some stuff\n");
/* Add file to the index */
cl_git_pass(git_index_add_bypath(index, "file.txt"));
cl_git_pass(git_index_write(index));
/* Create a commit with the new contents of the index */
{
git_signature *sig;
git_oid tree_id, commit_id;
git_tree *tree;
cl_git_pass(git_signature_default(&sig, _repo));
cl_git_pass(git_index_write_tree(&tree_id, index));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
cl_git_pass(git_commit_create_v(
&commit_id, _repo, "HEAD", sig, sig,
NULL, "First", tree, 0));
git_tree_free(tree);
git_signature_free(sig);
}
git_index_free(index);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment