# [PATCH v2] cherry-pick: allow "-" as abbreviation of '@{-1}'

2 messages from 2013-09-05 to 2013-09-05. Participants: Hiroshige Umino, Junio C Hamano.
Thread: https://gitlist.dev/t/34855

## Hiroshige Umino, 2013-09-05 14:57

Subject: [PATCH v2] cherry-pick: allow "-" as abbreviation of '@{-1}'
Message-ID: <1378393043-55403-1-git-send-email-hiroshige88@gmail.com>
URL: https://gitlist.dev/e/1378393043-55403-1-git-send-email-hiroshige88%40gmail.com

```
"-" 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>
---
 builtin/revert.c  |  2 ++
 t/t3500-cherry.sh | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/builtin/revert.c b/builtin/revert.c
index 8e87acd..52c35e7 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -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)
diff --git a/t/t3500-cherry.sh b/t/t3500-cherry.sh
index f038f34..547dbf8 100755
--- a/t/t3500-cherry.sh
+++ b/t/t3500-cherry.sh
@@ -55,4 +55,19 @@ test_expect_success \
      expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
 '
 
+test_expect_success \
+    '"cherry-pick -" does not work initially' \
+    'test_must_fail git cherry-pick -
+'
+
+test_expect_success \
+    'cherry-pick the commit in the previous branch' \
+    'git branch other &&
+     test_commit commit-to-pick newfile content &&
+     echo content >expected &&
+     git checkout other &&
+     git cherry-pick - &&
+     test_cmp expected newfile
+'
+
 test_done
-- 
1.8.3.4

```

## Junio C Hamano, 2013-09-05 22:30

Subject: Re: [PATCH v2] cherry-pick: allow "-" as abbreviation of '@{-1}'
Message-ID: <xmqq4n9yhpg4.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq4n9yhpg4.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1378393043-55403-1-git-send-email-hiroshige88@gmail.com>

```
Hiroshige Umino <hiroshige88@gmail.com> writes:

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

This makes sense to me.

The test t3500 is about "git cherry" command, so I came up with a
tweak to move it to t3501, which is about cherry-pick, on top of
this patch.  Will tentatively queue this patch with that tweak to
'pu'.

Thanks.

>  builtin/revert.c  |  2 ++
>  t/t3500-cherry.sh | 15 +++++++++++++++
>  2 files changed, 17 insertions(+)
>
> diff --git a/builtin/revert.c b/builtin/revert.c
> index 8e87acd..52c35e7 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -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)
> diff --git a/t/t3500-cherry.sh b/t/t3500-cherry.sh
> index f038f34..547dbf8 100755
> --- a/t/t3500-cherry.sh
> +++ b/t/t3500-cherry.sh
> @@ -55,4 +55,19 @@ test_expect_success \
>       expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
>  '
>  
> +test_expect_success \
> +    '"cherry-pick -" does not work initially' \
> +    'test_must_fail git cherry-pick -
> +'
> +
> +test_expect_success \
> +    'cherry-pick the commit in the previous branch' \
> +    'git branch other &&
> +     test_commit commit-to-pick newfile content &&
> +     echo content >expected &&
> +     git checkout other &&
> +     git cherry-pick - &&
> +     test_cmp expected newfile
> +'
> +
>  test_done

```
