Skip to content

Commit 68e3558

Browse files
committed
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.
1 parent 63460fe commit 68e3558

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/refspec.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
155155
return 0;
156156

157157
invalid:
158-
git_error_set(
159-
GIT_ERROR_INVALID,
160-
"'%s' is not a valid refspec.", input);
158+
git_error_set(GIT_ERROR_INVALID,
159+
"'%s' is not a valid refspec.", input);
160+
git_refspec__dispose(refspec);
161+
return GIT_EINVALIDSPEC;
161162

162163
on_error:
163-
git_refspec__dispose(refspec);
164+
git_refspec__dispose(refspec);
164165
return -1;
165166
}
166167

src/remote.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,8 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
110110
if ((error = ensure_remote_name_is_valid(name)) < 0)
111111
return error;
112112

113-
if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) {
114-
if (git_error_last()->klass != GIT_ERROR_NOMEMORY)
115-
error = GIT_EINVALIDSPEC;
116-
113+
if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0)
117114
return error;
118-
}
119115

120116
git_refspec__dispose(&spec);
121117

tests/network/refspecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static void assert_refspec(unsigned int direction, const char *input, bool is_ex
1313
if (is_expected_to_be_valid)
1414
cl_assert_equal_i(0, error);
1515
else
16-
cl_assert_equal_i(GIT_ERROR, error);
16+
cl_assert_equal_i(GIT_EINVALIDSPEC, error);
1717
}
1818

1919
void test_network_refspecs__parsing(void)

0 commit comments

Comments
 (0)