cherry-pick: make sure all input objects are commits

When a single argument was a non-commit, the error message used to be: fatal: BUG: expected exactly one commit from walk For multiple arguments, when none of the arguments was a commit, the error was: fatal: empty commit set passed Finally, when some of the arguments were non-commits, we ignored those arguments. Fix this bug and make sure all arguments are commits, and for the first non-commit, error out with: fatal: <name>: Can't cherry-pick a <type> Signed-off-by: Miklos Vajna <vmiklos@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Miklos Vajna committed Apr 11, 2013 at 15:06 UTC 21246dbb9e0af278bc671e32e45a6cae4ad38b6f
2 files changed +24
sequencer.c
+18
@@ -1047,6 +1047,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
1047 {
1048 struct commit_list *todo_list = NULL;
1049 unsigned char sha1[20];
1050 + int i;
1051
1052 if (opts->subcommand == REPLAY_NONE)
1053 assert(opts->revs);
@@ -1067,6 +1068,23 @@ int sequencer_pick_revisions(struct replay_opts *opts)
1068 if (opts->subcommand == REPLAY_CONTINUE)
1069 return sequencer_continue(opts);
1070
1071 + for (i = 0; i < opts->revs->pending.nr; i++) {
1072 + unsigned char sha1[20];
1073 + const char *name = opts->revs->pending.objects[i].name;
1074 +
1075 + /* This happens when using --stdin. */
1076 + if (!strlen(name))
1077 + continue;
1078 +
1079 + if (!get_sha1(name, sha1)) {
1080 + enum object_type type = sha1_object_info(sha1, NULL);
1081 +
1082 + if (type > 0 && type != OBJ_COMMIT)
1083 + die(_("%s: can't cherry-pick a %s"), name, typename(type));
1084 + } else
1085 + die(_("%s: bad revision"), name);
1086 + }
1087 +
1088 /*
1089 * If we were called as "git cherry-pick <commit>", just
1090 * cherry-pick/revert it, set CHERRY_PICK_HEAD /
t/t3508-cherry-pick-many-commits.sh
+6
@@ -55,6 +55,12 @@ one
55 two"
56 '
57
58 +test_expect_success 'cherry-pick three one two: fails' '
59 + git checkout -f master &&
60 + git reset --hard first &&
61 + test_must_fail git cherry-pick three one two:
62 +'
63 +
64 test_expect_success 'output to keep user entertained during multi-pick' '
65 cat <<-\EOF >expected &&
66 [master OBJID] second