Commit 1bd2f795 by Edward Thomson

refspec: return GIT_EINVALIDSPEC for invalid specs

Disambiguate invalid specifications in `git_refspec__parse` so that
callers can determine the difference between invalid specifications and
actual errors.  No call sites wil propagagte this new error message to
an end-user, so there is no user-facing API change.
parent 9246d733
...@@ -155,12 +155,13 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) ...@@ -155,12 +155,13 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
return 0; return 0;
invalid: invalid:
git_error_set( git_error_set(GIT_ERROR_INVALID,
GIT_ERROR_INVALID, "'%s' is not a valid refspec.", input);
"'%s' is not a valid refspec.", input); git_refspec__dispose(refspec);
return GIT_EINVALIDSPEC;
on_error: on_error:
git_refspec__dispose(refspec); git_refspec__dispose(refspec);
return -1; return -1;
} }
......
...@@ -110,12 +110,8 @@ static int write_add_refspec(git_repository *repo, const char *name, const char ...@@ -110,12 +110,8 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
if ((error = ensure_remote_name_is_valid(name)) < 0) if ((error = ensure_remote_name_is_valid(name)) < 0)
return error; return error;
if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) { if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0)
if (git_error_last()->klass != GIT_ERROR_NOMEMORY)
error = GIT_EINVALIDSPEC;
return error; return error;
}
git_refspec__dispose(&spec); git_refspec__dispose(&spec);
......
...@@ -13,7 +13,7 @@ static void assert_refspec(unsigned int direction, const char *input, bool is_ex ...@@ -13,7 +13,7 @@ static void assert_refspec(unsigned int direction, const char *input, bool is_ex
if (is_expected_to_be_valid) if (is_expected_to_be_valid)
cl_assert_equal_i(0, error); cl_assert_equal_i(0, error);
else else
cl_assert_equal_i(GIT_ERROR, error); cl_assert_equal_i(GIT_EINVALIDSPEC, error);
} }
void test_network_refspecs__parsing(void) void test_network_refspecs__parsing(void)
......
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