cherry-pick: allow "-" as abbreviation of '@{-1}'

"-" 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>

Hiroshige Umino committed Sep 5, 2013 at 23:57 UTC 182d7dc46b23b4a20985c93ea3a6ba3e6f267ff6
2 files changed +22
builtin/revert.c
+2
@@ -232,6 +232,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
232 memset(&opts, 0, sizeof(opts));
233 opts.action = REPLAY_PICK;
234 git_config(git_default_config, NULL);
235 + if (!strcmp(argv[1], "-"))
236 + argv[1] = "@{-1}";
237 parse_args(argc, argv, &opts);
238 res = sequencer_pick_revisions(&opts);
239 if (res < 0)
t/t3501-revert-cherry-pick.sh
+20
@@ -109,4 +109,24 @@ test_expect_success 'chery-pick on unborn branch' '
109 ! test_cmp_rev initial HEAD
110 '
111
112 +test_expect_success 'cherry-pick "-" to pick from previous branch' '
113 + git checkout unborn &&
114 + test_commit to-pick actual content &&
115 + git checkout master &&
116 + git cherry-pick - &&
117 + echo content >expect &&
118 + test_cmp expect actual
119 +'
120 +
121 +test_expect_success 'cherry-pick "-" is meaningless without checkout' '
122 + test_create_repo afresh &&
123 + (
124 + cd afresh &&
125 + test_commit one &&
126 + test_commit two &&
127 + test_commit three &&
128 + test_must_fail git cherry-pick -
129 + )
130 +'
131 +
132 test_done