git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cherry-pick: allow "-" as abbreviation of '@{-1}'
@ 2013-08-03  5:15 Hiroshige Umino
  2013-08-03 10:51 ` Thomas Rast
  0 siblings, 1 reply; 4+ messages in thread
From: Hiroshige Umino @ 2013-08-03  5:15 UTC (permalink / raw)
  To: git; +Cc: Hiroshige Umino

As "git cherry-pick -" or "git merge -" is convenient to
switch back to or merge the previous branch,
"git cherry-pick -" is abbreviation of "git cherry-pick @{-1}"
to pick up a commit from the previous branch conveniently.

Signed-off-by: Hiroshige Umino <hiroshige88@gmail.com>
---
 builtin/revert.c            |  2 ++
 t/t3512-cherry-pick-last.sh | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100755 t/t3512-cherry-pick-last.sh

diff --git a/builtin/revert.c b/builtin/revert.c
index 1d2648b..cb403f8 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -234,6 +234,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/t3512-cherry-pick-last.sh b/t/t3512-cherry-pick-last.sh
new file mode 100755
index 0000000..8b05f81
--- /dev/null
+++ b/t/t3512-cherry-pick-last.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+test_description='Test cherry-pick -'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo hello >world &&
+ git add world &&
+ git commit -m initial &&
+ git branch other &&
+ echo "hello again" >>world &&
+ git add world &&
+ git commit -m second
+'
+
+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' '
+ prev=$(git rev-parse HEAD) &&
+ git checkout other &&
+ git cherry-pick - &&
+ test "z$(git rev-parse HEAD)" = "z$prev"
+'
+
+test_done
-- 
1.8.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-16 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-03  5:15 [PATCH] cherry-pick: allow "-" as abbreviation of '@{-1}' Hiroshige Umino
2013-08-03 10:51 ` Thomas Rast
2013-08-05 16:27   ` Junio C Hamano
2013-08-16 15:17     ` Hiroshige Umino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).