diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-08-29 16:19:34 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-09-07 00:47:28 +0400 |
commit | 4047950f30618c160cd2fdf5da39fb8e26b031d9 (patch) | |
tree | bd6682f4c713b9a012582a0cffe60137c24b235d /tests-clar/object | |
parent | ae4a486605c258aa38a53534c99f94e66379c9ae (diff) |
odb: Prevent stream_finalize_write() from overwriting
Now that #1785 is merged, git_odb_stream_finalize_write() calculates the object id before invoking the odb backend.
This commit gives a chance to the backend to check if it already knows this object.
Diffstat (limited to 'tests-clar/object')
-rw-r--r-- | tests-clar/object/blob/fromchunks.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests-clar/object/blob/fromchunks.c b/tests-clar/object/blob/fromchunks.c index 9fe62daef..03ed4efb4 100644 --- a/tests-clar/object/blob/fromchunks.c +++ b/tests-clar/object/blob/fromchunks.c @@ -53,6 +53,34 @@ void test_object_blob_fromchunks__can_create_a_blob_from_a_in_memory_chunk_provi git_object_free(blob); } +void test_object_blob_fromchunks__doesnot_overwrite_an_already_existing_object(void) +{ + git_buf path = GIT_BUF_INIT; + git_buf content = GIT_BUF_INIT; + git_oid expected_oid, oid; + int howmany = 7; + + cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); + + cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); + + /* Let's replace the content of the blob file storage with something else... */ + cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/32/1cbdf08803c744082332332838df6bd160f8f9")); + cl_git_pass(p_unlink(git_buf_cstr(&path))); + cl_git_mkfile(git_buf_cstr(&path), "boom"); + + /* ...request a creation of the same blob... */ + howmany = 7; + cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); + + /* ...and ensure the content of the faked blob file hasn't been altered */ + cl_git_pass(git_futils_readbuffer(&content, git_buf_cstr(&path))); + cl_assert(!git__strcmp("boom", git_buf_cstr(&content))); + + git_buf_free(&path); + git_buf_free(&content); +} + #define GITATTR "* text=auto\n" \ "*.txt text\n" \ "*.data binary\n" |