Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e2e824

Browse files
carlosmnEdward Thomson
authored and
Edward Thomson
committed
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.
1 parent ab062a3 commit 3e2e824

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/refs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
289289
"Could not use '%s' as valid reference name", git_buf_cstr(&name));
290290
}
291291

292+
if (error == GIT_ENOTFOUND)
293+
giterr_set(GITERR_REFERENCE, "no reference found for shorthand '%s'", refname);
294+
292295
git_buf_free(&name);
293296
git_buf_free(&refnamebuf);
294297
return error;

tests/refs/lookup.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ void test_refs_lookup__namespace(void)
5858
error = git_reference_lookup(&ref, g_repo, "refs/heads/");
5959
cl_assert_equal_i(error, GIT_EINVALIDSPEC);
6060
}
61+
62+
void test_refs_lookup__dwim_notfound(void)
63+
{
64+
git_reference *ref;
65+
66+
cl_git_fail_with(GIT_ENOTFOUND, git_reference_dwim(&ref, g_repo, "idontexist"));
67+
cl_assert_equal_s("no reference found for shorthand 'idontexist'", giterr_last()->message);
68+
}

0 commit comments

Comments
 (0)