Commit 279b45b0 by Carlos Martín Nieto

revparse: don't allow an empty string

Asking the library for "" used to give HEAD, but that's trying to
impose a default at the wrong layer. Make it fail.
parent 14e1bc15
......@@ -705,7 +705,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
*out = NULL;
do {
while (spec[pos]) {
switch (spec[pos]) {
case '^':
if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
......@@ -813,9 +813,9 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
pos++;
identifier_len++;
}
} while (spec[pos]);
}
if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
goto cleanup;
*out = base_rev;
......
......@@ -64,6 +64,8 @@ void test_refs_revparse__invalid_reference_name(void)
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense^1"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense~2"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, ""));
}
void test_refs_revparse__shas(void)
......@@ -74,7 +76,6 @@ void test_refs_revparse__shas(void)
void test_refs_revparse__head(void)
{
test_object("", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("HEAD^0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("HEAD~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment