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

2013-09-05 Thread Hiroshige Umino
"-" 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 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-16 Thread Hiroshige Umino
Junio C Hamano  wrote:
> Thomas Rast  writes:
> 
>> Hiroshige Umino  writes:
>>
>>> 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.
>>
>> The first line is confusing.  Did you mean to invoke the existing 'git
>> *checkout* -' and 'git merge -' functionality as a reason why 'git
>> cherry-pick -' should exist?
> 
> I think that is what was meant.  Just like "-" abbreviation is handy
> for users of "checkout" and "merge", "cherry-pick" might.

Yes I meant so and it would be useful at least for me.
I don't know the usage of cherry-pick (pick up a commit from the previous
branch) is comon or not but it may be also good for consistency.


Thomas Rast  wrote:
> What other commands could reasonably use the '-' shorthand?

I've wanted '-' shorthand only for commit, merge and cherry-pick
but 'git diff -' may make sense.
What do you think of this and other candidates?

> Do you have to use a new test file for this?
Not have to so I'm moving the tests into t/t3500-cherry.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
>> +'
> 
> Our style is to indent the test snippets with a hard tab, not a single
> (or eight, for that matter) space.
> 
> [...]
>> +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"
>> +'
> 
> If you insert 'test_tick' in the places marked with (*), the test fails.
> 
> The tests run under a fake clock to ensure that everything, including
> the SHA1s produced, are deterministic.  You never advance the clock, so
> all commits generated in this script share the same timestamp.
> 
> This means that the cherry-pick of 'second' has the same SHA1 as the
> original: its tree, parents, author, timestamp etc. all agree.  If you
> advance the clock at the last (*), this fails.  You should find some
> other way of checking what was picked, e.g., by looking at the file
> contents.
> 
> That said, please use test_commit in the 'setup' snippet instead of
> manually rolling the commits.  It will lead to shorter code, and it
> handles test_tick for you.  It is documented in t/README and in a
> comment in t/test-lib-functions.sh.  (You still need test_tick
> immediately before the cherry-pick!)

I overlooked t/README, thank you for kindly guiding testing!

--
Hiroshige UMINO @yaotti
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-02 Thread 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 
---
 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 000..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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html