cherry-pick: allow to pick to unborn branches
authorMichael J Gruber <git@drmicha.warpmail.net>
Mon, 6 Jun 2016 13:23:54 +0000 (15:23 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Jun 2016 19:59:28 +0000 (12:59 -0700)
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>
sequencer.c
index c4f4b7d571fa088f80a0dbba815491a35f0c153f..c051d134c2398b3d227ae42e1d54d77846ebb904 100644 (file)
@@ -919,6 +919,10 @@ static int sequencer_rollback(struct replay_opts *opts)
                        filename);
                goto fail;
        }
+       if (is_null_sha1(sha1)) {
+               error(_("cannot abort from a branch yet to be born"));
+               goto fail;
+       }
        if (reset_for_rollback(sha1))
                goto fail;
        remove_sequencer_state();
@@ -1118,11 +1122,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
        walk_revs_populate_todo(&todo_list, opts);
        if (create_seq_dir() < 0)
                return -1;
-       if (get_sha1("HEAD", sha1)) {
-               if (opts->action == REPLAY_REVERT)
-                       return error(_("Can't revert as initial commit"));
-               return error(_("Can't cherry-pick into empty head"));
-       }
+       if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT))
+               return error(_("Can't revert as initial commit"));
        save_head(sha1_to_hex(sha1));
        save_opts(opts);
        return pick_commits(todo_list, opts);