Skip to content

Commit d94cecf

Browse files
committed
Merge branch 'jk/empty-pick-fix'
Handling of an empty range by "git cherry-pick" was inconsistent depending on how the range ended up to be empty, which has been corrected. * jk/empty-pick-fix: sequencer: don't say BUG on bogus input sequencer: handle empty-set cases consistently
2 parents 9cb10ca + c5e358d commit d94cecf

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sequencer.c

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

1867-
if (!opts->revs->commits)
1868-
return error(_("empty commit set passed"));
18691867
return 0;
18701868
}
18711869

@@ -2323,6 +2321,10 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
23232321
short_commit_name(commit), subject_len, subject);
23242322
unuse_commit_buffer(commit, commit_buffer);
23252323
}
2324+
2325+
if (!todo_list->nr)
2326+
return error(_("empty commit set passed"));
2327+
23262328
return 0;
23272329
}
23282330

@@ -3658,8 +3660,10 @@ int sequencer_pick_revisions(struct replay_opts *opts)
36583660
if (prepare_revision_walk(opts->revs))
36593661
return error(_("revision walk setup failed"));
36603662
cmit = get_revision(opts->revs);
3661-
if (!cmit || get_revision(opts->revs))
3662-
return error("BUG: expected exactly one commit from walk");
3663+
if (!cmit)
3664+
return error(_("empty commit set passed"));
3665+
if (get_revision(opts->revs))
3666+
BUG("unexpected extra commit from walk");
36633667
return single_pick(cmit, opts);
36643668
}
36653669

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)