diff options
author | Vicent Martà <vicent@github.com> | 2012-09-28 11:57:02 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-09-28 11:57:02 -0700 |
commit | 34402bcdb94ff412e66220ada0b776c25cd8c30d (patch) | |
tree | 293c426c922de1e12e4da6a5d39a4fcf3d3843f2 | |
parent | 3f849902e4b20216c80ec69714d6a6a0fdd332d2 (diff) | |
parent | addc9be4fcb88e77107557e991bd92355522d844 (diff) | |
download | libgit2-34402bcdb94ff412e66220ada0b776c25cd8c30d.tar.gz |
Merge pull request #959 from jamill/empty_file_hash
Fix error hashing empty file.
-rw-r--r-- | src/odb.c | 2 | ||||
-rw-r--r-- | tests-clar/status/single.c | 16 |
2 files changed, 17 insertions, 1 deletions
@@ -115,7 +115,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type) int hdr_len; char hdr[64], buffer[2048]; git_hash_ctx *ctx; - ssize_t read_len = -1; + ssize_t read_len = 0; if (!git_object_typeisloose(type)) { giterr_set(GITERR_INVALID, "Invalid object type for hash"); diff --git a/tests-clar/status/single.c b/tests-clar/status/single.c index e900a31d6..292c9120a 100644 --- a/tests-clar/status/single.c +++ b/tests-clar/status/single.c @@ -25,5 +25,21 @@ void test_status_single__hash_single_file(void) cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); } +/* test retrieving OID from an empty file apart from the ODB */ +void test_status_single__hash_single_empty_file(void) +{ + static const char file_name[] = "new_empty_file"; + static const char file_contents[] = ""; + static const char file_hash[] = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"; + + git_oid expected_id, actual_id; + /* initialization */ + git_oid_fromstr(&expected_id, file_hash); + cl_git_mkfile(file_name, file_contents); + cl_set_cleanup(&cleanup__remove_file, (void *)file_name); + + cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); + cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); +} |