sequencer: handle empty-set cases consistently
authorJeff King <peff@peff.net>
Mon, 9 Jul 2018 19:48:19 +0000 (15:48 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Jul 2018 15:37:47 +0000 (08:37 -0700)
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 7e2bfd3f99 (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 <peff@peff.net>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3510-cherry-pick-sequence.sh
index 4d3f60594cbf0e9ddf2ea78e8c58eca312b4cac0..7fbacc10214c4cf22e605f118795636fc4c2f8d0 100644 (file)
@@ -1176,8 +1176,6 @@ static int prepare_revs(struct replay_opts *opts)
        if (prepare_revision_walk(opts->revs))
                return error(_("revision walk setup failed"));
 
-       if (!opts->revs->commits)
-               return error(_("empty commit set passed"));
        return 0;
 }
 
@@ -1560,6 +1558,10 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
                        short_commit_name(commit), subject_len, subject);
                unuse_commit_buffer(commit, commit_buffer);
        }
+
+       if (!todo_list->nr)
+               return error(_("empty commit set passed"));
+
        return 0;
 }
 
index 0acf4b14614c750d3c2324d8a941aa77d5c7ad56..6987bbfee5ff62410f94a337464225a1213ceda0 100755 (executable)
@@ -480,11 +480,16 @@ test_expect_success 'malformed instruction sheet 2' '
        test_expect_code 128 git cherry-pick --continue
 '
 
-test_expect_success 'empty commit set' '
+test_expect_success 'empty commit set (no commits to walk)' '
        pristine_detach initial &&
        test_expect_code 128 git cherry-pick base..base
 '
 
+test_expect_success 'empty commit set (culled during walk)' '
+       pristine_detach initial &&
+       test_expect_code 128 git cherry-pick -2 --author=no.such.author base
+'
+
 test_expect_success 'malformed instruction sheet 3' '
        pristine_detach initial &&
        test_expect_code 1 git cherry-pick base..anotherpick &&