git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Hiroshige Umino <hiroshige88@gmail.com>
Date
Aug 16, 2013, 15:17 UTC
Message-ID
<20130817.001737.1890599379619259228.xxx@gmail.com>
In-Reply-To
<7vmwowm7bc.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Thomas Rast <trast@inf.ethz.ch> writes:
> 
>> Hiroshige Umino <hiroshige88@gmail.com> 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 <trast@inf.ethz.ch> 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.
Show 42 quoted lines
> [...]
>> +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

Previous: Junio C Hamano
Message 4 of 4 in “cherry-pick: allow "-" as abbreviation of '@{-1}'”
  1. cherry-pick: allow "-" as abbreviation of '@{-1}'Hiroshige Umino, Aug 3, 2013
  2. Thomas RastAug 3, 2013
  3. Junio C HamanoAug 5, 2013
  4. Hiroshige UminoAug 16, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.