diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2016-02-16 14:06:48 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-02-16 14:06:48 +0100 |
commit | eadd0f05f6faf14f94876839f00981da5d642667 (patch) | |
tree | 7a7a4e431b5c95a1e62a013456c1ef07d76f4d32 /src/commit.c | |
parent | 1aa14921827244da8d0a736fff02b3ea293adf6e (diff) | |
download | libgit2-eadd0f05f6faf14f94876839f00981da5d642667.tar.gz |
commit: expose the different kinds of errors
We should be checking whether the object we're looking up is a commit,
and we should let the caller know whether the not-found return code
comes from a bad object type or just a missing signature.
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/commit.c b/src/commit.c index 8faef07df..5a0509803 100644 --- a/src/commit.c +++ b/src/commit.c @@ -642,6 +642,12 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r if ((error = git_odb_read(&obj, odb, commit_id)) < 0) return error; + if (obj->cached.type != GIT_OBJ_COMMIT) { + giterr_set(GITERR_INVALID, "the requested type does not match the type in ODB"); + error = GIT_ENOTFOUND; + goto cleanup; + } + buf = git_odb_object_data(obj); while ((h = strchr(buf, '\n')) && h[1] != '\0' && h[1] != '\n') { @@ -688,7 +694,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r return git_buf_puts(signed_data, eol+1); } - giterr_set(GITERR_INVALID, "this commit is not signed"); + giterr_set(GITERR_OBJECT, "this commit is not signed"); error = GIT_ENOTFOUND; goto cleanup; |