From cb0ce16bbe8efe2098ef9cfffcf158301b036565 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 7 May 2012 15:42:13 +0200 Subject: [PATCH] object: make git_object_lookup() return GIT_ENOTFOUND when searching for an existing object by specifying an incorrect type --- src/object.c | 4 ++-- tests-clar/object/lookup.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests-clar/object/lookup.c diff --git a/src/object.c b/src/object.c index e02bd69ba..02be5dac8 100644 --- a/src/object.c +++ b/src/object.c @@ -150,8 +150,8 @@ int git_object_lookup_prefix( if (type != GIT_OBJ_ANY && type != odb_obj->raw.type) { git_odb_object_free(odb_obj); - giterr_set(GITERR_INVALID, "The given type does not match the type on the ODB"); - return -1; + giterr_set(GITERR_ODB, "The given type does not match the type on the ODB"); + return GIT_ENOTFOUND; } type = odb_obj->raw.type; diff --git a/tests-clar/object/lookup.c b/tests-clar/object/lookup.c new file mode 100644 index 000000000..4db2ecfbe --- /dev/null +++ b/tests-clar/object/lookup.c @@ -0,0 +1,35 @@ +#include "clar_libgit2.h" + +#include "repository.h" + +static git_repository *g_repo; + +void test_object_lookup__initialize(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git"))); +} + +void test_object_lookup__cleanup(void) +{ + git_repository_free(g_repo); +} + +void test_object_lookup__looking_up_an_exisiting_object_by_its_wrong_type_returns_ENOTFOUND(void) +{ + const char *commit = "e90810b8df3e80c413d903f631643c716887138d"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid_fromstr(&oid, commit)); + cl_assert_equal_i(GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_TAG)); +} + +void test_object_lookup__looking_up_a_non_exisiting_object_returns_ENOTFOUND(void) +{ + const char *unknown = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid_fromstr(&oid, unknown)); + cl_assert_equal_i(GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_ANY)); +}