From 77965c685d0ca8d5dc65ba3aedb41cca5485ae04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 11 Apr 2016 17:43:07 +0200 Subject: [PATCH] refs: provide a more general error message for dwim If we cannot dwim the input, set the error message to be explicit about that. Otherwise we leave the error for the last failed lookup, which can be rather unexpected as it mentions a remote when the user thought they were trying to look up a branch. --- src/refs.c | 3 +++ tests/refs/lookup.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/refs.c b/src/refs.c index a15e31b53..26c80021f 100644 --- a/src/refs.c +++ b/src/refs.c @@ -289,6 +289,9 @@ cleanup: "Could not use '%s' as valid reference name", git_buf_cstr(&name)); } + if (error == GIT_ENOTFOUND) + giterr_set(GITERR_REFERENCE, "no reference found for shorthand '%s'", refname); + git_buf_free(&name); git_buf_free(&refnamebuf); return error; diff --git a/tests/refs/lookup.c b/tests/refs/lookup.c index d076e491f..456d0d2a8 100644 --- a/tests/refs/lookup.c +++ b/tests/refs/lookup.c @@ -58,3 +58,11 @@ void test_refs_lookup__namespace(void) error = git_reference_lookup(&ref, g_repo, "refs/heads/"); cl_assert_equal_i(error, GIT_EINVALIDSPEC); } + +void test_refs_lookup__dwim_notfound(void) +{ + git_reference *ref; + + cl_git_fail_with(GIT_ENOTFOUND, git_reference_dwim(&ref, g_repo, "idontexist")); + cl_assert_equal_s("no reference found for shorthand 'idontexist'", giterr_last()->message); +}