diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-11 13:35:35 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-25 16:33:27 +0000 |
commit | 68e35588ad5b55c9f0357e0a33f7282c0a454a0c (patch) | |
tree | 37544c3c2b8107ed6e643280567fe34dc1f2d187 | |
parent | 63460fe4b5616cce01e4b67f0994e2e75415324d (diff) | |
download | libgit2-68e35588ad5b55c9f0357e0a33f7282c0a454a0c.tar.gz |
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.
-rw-r--r-- | src/refspec.c | 9 | ||||
-rw-r--r-- | src/remote.c | 6 | ||||
-rw-r--r-- | tests/network/refspecs.c | 2 |
3 files changed, 7 insertions, 10 deletions
diff --git a/src/refspec.c b/src/refspec.c index 95b2830f8..4245cbbda 100644 --- a/src/refspec.c +++ b/src/refspec.c @@ -155,12 +155,13 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) return 0; invalid: - git_error_set( - GIT_ERROR_INVALID, - "'%s' is not a valid refspec.", input); + git_error_set(GIT_ERROR_INVALID, + "'%s' is not a valid refspec.", input); + git_refspec__dispose(refspec); + return GIT_EINVALIDSPEC; on_error: - git_refspec__dispose(refspec); + git_refspec__dispose(refspec); return -1; } diff --git a/src/remote.c b/src/remote.c index b69526c42..9c795ee84 100644 --- a/src/remote.c +++ b/src/remote.c @@ -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) return error; - if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) { - if (git_error_last()->klass != GIT_ERROR_NOMEMORY) - error = GIT_EINVALIDSPEC; - + if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) return error; - } git_refspec__dispose(&spec); diff --git a/tests/network/refspecs.c b/tests/network/refspecs.c index 5c8eb1502..d9e0d9e8d 100644 --- a/tests/network/refspecs.c +++ b/tests/network/refspecs.c @@ -13,7 +13,7 @@ static void assert_refspec(unsigned int direction, const char *input, bool is_ex if (is_expected_to_be_valid) cl_assert_equal_i(0, error); else - cl_assert_equal_i(GIT_ERROR, error); + cl_assert_equal_i(GIT_EINVALIDSPEC, error); } void test_network_refspecs__parsing(void) |