Skip to content

Commit d55bb47

Browse files
committed
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.
1 parent af95615 commit d55bb47

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/revwalk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
194194
if ((error = git_revparse(&revspec, walk->repo, range)))
195195
return error;
196196

197+
if (!revspec.to) {
198+
git_error_set(GIT_ERROR_INVALID, "invalid revspec. Only range supported.");
199+
error = GIT_EINVALIDSPEC;
200+
goto out;
201+
}
202+
197203
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
198204
/* TODO: support "<commit>...<commit>" */
199205
git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk");

tests/revwalk/basic.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,15 @@ void test_revwalk_basic__push_range(void)
400400
cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 2));
401401
}
402402

403+
void test_revwalk_basic__push_range_no_range(void)
404+
{
405+
revwalk_basic_setup_walk(NULL);
406+
407+
git_revwalk_reset(_walk);
408+
git_revwalk_sorting(_walk, 0);
409+
cl_git_fail_with(GIT_EINVALIDSPEC, git_revwalk_push_range(_walk, "HEAD"));
410+
}
411+
403412
void test_revwalk_basic__push_mixed(void)
404413
{
405414
git_oid oid;

0 commit comments

Comments
 (0)