int git_blob_writefile(git_oid *written_id, git_repository *repo, const char *path) { int error; git_blob *blob; if (gitfo_exists(path) < 0) return GIT_ENOTFOUND; if ((error = git_blob_new(&blob, repo)) < GIT_SUCCESS) return error; if ((error = git_blob_set_rawcontent_fromfile(blob, path)) < GIT_SUCCESS) return error; if ((error = git_object_write((git_object *)blob)) < GIT_SUCCESS) return error; git_oid_cpy(written_id, git_object_id((git_object *)blob)); /* FIXME: maybe we don't want to free this already? * the user may want to access it again */ GIT_OBJECT_DECREF(repo, blob); return GIT_SUCCESS; }
#include <git2/revwalk.h> static const char *tag_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"; BEGIN_TEST(tag_writeback_test) git_oid id; git_repository *repo; git_tag *tag; /* char hex_oid[41]; */ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); git_oid_mkstr(&id, tag_id); must_pass(git_tag_lookup(&tag, repo, &id)); git_tag_set_name(tag, "This is a different tag LOL"); must_pass(git_object_write((git_object *)tag)); /* git_oid_fmt(hex_oid, git_tag_id(tag)); hex_oid[40] = 0; printf("TAG New SHA1: %s\n", hex_oid); */ must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag)); git_repository_free(repo); END_TEST
must_be_true(committer->when.time == 123456789); must_be_true(committer->when.offset == 60); must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0); /* add new tree */ git_oid_mkstr(&id, tree_oid); must_pass(git_tree_lookup(&tree, repo, &id)); git_commit_set_tree(commit, tree); /* Test it has no OID */ must_be_true(git_commit_id(commit) == NULL); /* Write to disk */ must_pass(git_object_write((git_object *)commit)); must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); git_repository_free(repo); END_TEST BEGIN_TEST(writeback_test) git_repository *repo; git_oid id; git_commit *commit, *parent; const char *message; /* char hex_oid[41]; */ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));