Merge branch 'hu/cherry-pick-previous-branch'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:29:57 +0000 (12:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:29:58 +0000 (12:29 -0700)
Just like "git checkout -" knows to check out and "git merge -"
knows to merge the branch you were previously on, "git cherry-pick"
now understands "git cherry-pick -" to pick from the previous
branch.

* hu/cherry-pick-previous-branch:
cherry-pick: allow "-" as abbreviation of '@{-1}'

builtin/revert.c
t/t3501-revert-cherry-pick.sh
index 8e87acd12e622957df6bc0a93903898361149f91..52c35e75d90dc07f6a80362f200212e314a14ec8 100644 (file)
@@ -202,6 +202,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 46aaf2f511f6d37e8552d0b12fa64f7e30accd1d..bff6ffe08817ed0c057909aa1d3f93140cf6a3e0 100755 (executable)
@@ -109,4 +109,24 @@ test_expect_success 'cherry-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