Skip to content

Commit 8530c73

Browse files
peffgitster
authored andcommitted
sequencer: handle empty-set cases consistently
If the user gives us a set that prepare_revision_walk() takes to be empty, like: git cherry-pick base..base then we report an error. It's nonsense, and there's nothing to pick. But if they use revision options that later cull the list, like: git cherry-pick --author=nobody base~2..base then we quietly create an empty todo list and return success. Arguably either behavior is acceptable, but we should definitely be consistent about it. Reporting an error seems to match the original intent, which dates all the way back to 7e2bfd3 (revert: allow cherry-picking more than one commit, 2010-06-02). That in turn was trying to match the single-commit case that existed before then (and which continues to issue an error). Signed-off-by: Jeff King <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a42a58d commit 8530c73

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sequencer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,6 @@ static int prepare_revs(struct replay_opts *opts)
11761176
if (prepare_revision_walk(opts->revs))
11771177
return error(_("revision walk setup failed"));
11781178

1179-
if (!opts->revs->commits)
1180-
return error(_("empty commit set passed"));
11811179
return 0;
11821180
}
11831181

@@ -1560,6 +1558,10 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
15601558
short_commit_name(commit), subject_len, subject);
15611559
unuse_commit_buffer(commit, commit_buffer);
15621560
}
1561+
1562+
if (!todo_list->nr)
1563+
return error(_("empty commit set passed"));
1564+
15631565
return 0;
15641566
}
15651567

t/t3510-cherry-pick-sequence.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,16 @@ test_expect_success 'malformed instruction sheet 2' '
480480
test_expect_code 128 git cherry-pick --continue
481481
'
482482

483-
test_expect_success 'empty commit set' '
483+
test_expect_success 'empty commit set (no commits to walk)' '
484484
pristine_detach initial &&
485485
test_expect_code 128 git cherry-pick base..base
486486
'
487487

488+
test_expect_success 'empty commit set (culled during walk)' '
489+
pristine_detach initial &&
490+
test_expect_code 128 git cherry-pick -2 --author=no.such.author base
491+
'
492+
488493
test_expect_success 'malformed instruction sheet 3' '
489494
pristine_detach initial &&
490495
test_expect_code 1 git cherry-pick base..anotherpick &&

0 commit comments

Comments
 (0)