Skip to content

Commit 182d7dc

Browse files
yaottigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5be297 commit 182d7dc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

builtin/revert.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
232232
memset(&opts, 0, sizeof(opts));
233233
opts.action = REPLAY_PICK;
234234
git_config(git_default_config, NULL);
235+
if (!strcmp(argv[1], "-"))
236+
argv[1] = "@{-1}";
235237
parse_args(argc, argv, &opts);
236238
res = sequencer_pick_revisions(&opts);
237239
if (res < 0)

t/t3501-revert-cherry-pick.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,24 @@ test_expect_success 'chery-pick on unborn branch' '
109109
! test_cmp_rev initial HEAD
110110
'
111111

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+
112132
test_done

0 commit comments

Comments
 (0)