cherry-pick: allow to pick to unborn branches

cherry-pick allows to pick single commits to an empty HEAD, but not multiple commits. Allow the multiple commit case, too. Reported-by: Fabrizio Cucci <fabrizio.cucci@gmail.com> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Jun 6, 2016 at 15:23 UTC 0f974e2124e5220674eee079988b87e23f5e2de1
1 file changed +6 -5
sequencer.c
+6 -5
@@ -919,6 +919,10 @@ static int sequencer_rollback(struct replay_opts *opts)
919 filename);
920 goto fail;
921 }
922 + if (is_null_sha1(sha1)) {
923 + error(_("cannot abort from a branch yet to be born"));
924 + goto fail;
925 + }
926 if (reset_for_rollback(sha1))
927 goto fail;
928 remove_sequencer_state();
@@ -1118,11 +1122,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
1122 walk_revs_populate_todo(&todo_list, opts);
1123 if (create_seq_dir() < 0)
1124 return -1;
1121 - if (get_sha1("HEAD", sha1)) {
1122 - if (opts->action == REPLAY_REVERT)
1123 - return error(_("Can't revert as initial commit"));
1124 - return error(_("Can't cherry-pick into empty head"));
1125 - }
1125 + if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT))
1126 + return error(_("Can't revert as initial commit"));
1127 save_head(sha1_to_hex(sha1));
1128 save_opts(opts);
1129 return pick_commits(todo_list, opts);