cherry-pick: allow "-" as abbreviation of '@{-1}'
authorHiroshige Umino <hiroshige88@gmail.com>
Thu, 5 Sep 2013 14:57:23 +0000 (23:57 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Sep 2013 18:17:11 +0000 (11:17 -0700)
"-" abbreviation is handy for "cherry-pick" like "checkout" and "merge".

It's also good for uniformity that a "-" stands as
the name of the previous branch where a branch name is
accepted and it could not mean any other things like stdin.

Signed-off-by: Hiroshige Umino <hiroshige88@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/revert.c
t/t3501-revert-cherry-pick.sh
index 0401fdb02cbbcb6ac885c82ee2850fb931fc54ba..e264a151ea99628646374c6f072db1fa4c1ea47c 100644 (file)
@@ -232,6 +232,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
        memset(&opts, 0, sizeof(opts));
        opts.action = REPLAY_PICK;
        git_config(git_default_config, NULL);
+       if (!strcmp(argv[1], "-"))
+               argv[1] = "@{-1}";
        parse_args(argc, argv, &opts);
        res = sequencer_pick_revisions(&opts);
        if (res < 0)
index 6f489e20eecb48c6e1a2dc2b1fe90e47e7b3e7ad..6281619141afec8cc2d3a0696bbed4ec91e32b54 100755 (executable)
@@ -109,4 +109,24 @@ test_expect_success 'chery-pick on unborn branch' '
        ! test_cmp_rev initial HEAD
 '
 
+test_expect_success 'cherry-pick "-" to pick from previous branch' '
+       git checkout unborn &&
+       test_commit to-pick actual content &&
+       git checkout master &&
+       git cherry-pick - &&
+       echo content >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick "-" is meaningless without checkout' '
+       test_create_repo afresh &&
+       (
+               cd afresh &&
+               test_commit one &&
+               test_commit two &&
+               test_commit three &&
+               test_must_fail git cherry-pick -
+       )
+'
+
 test_done