Commit d55bb479 by Heiko Voigt

git_revwalk_push_range: do not crash if range is missing

If someone passes just one ref (i.e. "master") and misses passing the
range we should be nice and return an error code instead of crashing.
parent af95615f
...@@ -194,6 +194,12 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range) ...@@ -194,6 +194,12 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
if ((error = git_revparse(&revspec, walk->repo, range))) if ((error = git_revparse(&revspec, walk->repo, range)))
return error; return error;
if (!revspec.to) {
git_error_set(GIT_ERROR_INVALID, "invalid revspec. Only range supported.");
error = GIT_EINVALIDSPEC;
goto out;
}
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */ /* TODO: support "<commit>...<commit>" */
git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk"); git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk");
......
...@@ -400,6 +400,15 @@ void test_revwalk_basic__push_range(void) ...@@ -400,6 +400,15 @@ void test_revwalk_basic__push_range(void)
cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 2)); cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 2));
} }
void test_revwalk_basic__push_range_no_range(void)
{
revwalk_basic_setup_walk(NULL);
git_revwalk_reset(_walk);
git_revwalk_sorting(_walk, 0);
cl_git_fail_with(GIT_EINVALIDSPEC, git_revwalk_push_range(_walk, "HEAD"));
}
void test_revwalk_basic__push_mixed(void) void test_revwalk_basic__push_mixed(void)
{ {
git_oid oid; git_oid oid;
......
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