Skip to content

Commit 21246db

Browse files
Miklos Vajnagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa7285d commit 21246db

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

sequencer.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
10471047
{
10481048
struct commit_list *todo_list = NULL;
10491049
unsigned char sha1[20];
1050+
int i;
10501051

10511052
if (opts->subcommand == REPLAY_NONE)
10521053
assert(opts->revs);
@@ -1067,6 +1068,23 @@ int sequencer_pick_revisions(struct replay_opts *opts)
10671068
if (opts->subcommand == REPLAY_CONTINUE)
10681069
return sequencer_continue(opts);
10691070

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+
10701088
/*
10711089
* If we were called as "git cherry-pick <commit>", just
10721090
* cherry-pick/revert it, set CHERRY_PICK_HEAD /

t/t3508-cherry-pick-many-commits.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ one
5555
two"
5656
'
5757

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+
5864
test_expect_success 'output to keep user entertained during multi-pick' '
5965
cat <<-\EOF >expected &&
6066
[master OBJID] second

0 commit comments

Comments
 (0)