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

Re: Bug report: reset -p HEAD

From
MVMaarten de Vries <maarten@de-vri.es>
Date
Oct 24, 2013, 23:16 UTC
Message-ID
<CAPWpf+zkA68pzR3qx5xma8BNiONwt5o8iNba0x8fmmiDAWpHuw@mail.gmail.com>
In-Reply-To
<CAPWpf+x5KUjD2K81pJAsV_XuPkd=BT06qPjvr8s7tEe5YqBt=w@mail.gmail.com>

Some more info: It used to work as intended. Using a bisect shows it has been broken by commit 166ec2e9.

Kinds regards, Maarten de Vries

On 25 October 2013 01:05, Maarten de Vries <maarten@de-vri.es> wrote:
Show 58 quoted lines
> Hi,
>
> I noticed that reset -p HEAD is inconsistent with checkout -p HEAD.
> When running checkout -p you are asked to discard hunks from the index
> and worktree, but when running reset -p you are asked to apply hunks
> to the index. It would make more sense if reset -p asked to discard
> (reversed) hunks from the index.
>
> Digging a bit further, it looks like reset -p is actually intended to
> show hunks to discard when resetting to HEAD. The
> git-add--interactive.perl script has different cases for resetting to
> the head and for resetting to anything else. However, builtin/reset.c
> always passes a hash to run_add_interactive, even if HEAD is provided
> explicitly on the command line or no revision is given. As a result,
> the special case for resetting to the HEAD is never triggered and
> git-add--interactive.perl always asks to apply hunks rather than
> discard the reverse hunks.
>
> The offending part in builtin/reset.c is on line 307. It's the bit
> with sha1_to_hex(sha1):
>>     if (patch_mode) {
>>         if (reset_type != NONE)
>>             die(_("--patch is incompatible with --{hard,mixed,soft}"));
>>         return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
>>     }
>
> I'm not familiar enough with the git source, but it's probably a
> fairly trivial fix for someone who is.
>
>
> Kind regards,
> Maarten de Vries
>
>
> P.S.
>
> This bit in git-add--interactive.perl convinced me that resetting to
> HEAD interactively should be handled separately:
>>     'reset_head' => {
>>         DIFF => 'diff-index -p --cached',
>>         APPLY => sub { apply_patch 'apply -R --cached', @_; },
>>         APPLY_CHECK => 'apply -R --cached',
>>         VERB => 'Unstage',
>>         TARGET => '',
>>         PARTICIPLE => 'unstaging',
>>         FILTER => 'index-only',
>>         IS_REVERSE => 1,
>>     },
>>     'reset_nothead' => {
>>         DIFF => 'diff-index -R -p --cached',
>>         APPLY => sub { apply_patch 'apply --cached', @_; },
>>         APPLY_CHECK => 'apply --cached',
>>         VERB => 'Apply',
>>         TARGET => ' to index',
>>         PARTICIPLE => 'applying',
>>         FILTER => 'index-only',
>>         IS_REVERSE => 0,
>>     },
Previous: Maarten de VriesNext: Junio C Hamano
Message 2 of 9 in “Fwd: Bug report: reset -p HEAD”
  1. Maarten de VriesOct 24, 2013
  2. Maarten de VriesOct 24, 2013
  3. Re* Bug report: reset -p HEADJunio C Hamano, Oct 25, 2013
  4. Jeff KingOct 25, 2013
  5. Martin von ZweigbergkOct 25, 2013
  6. 0/2 reset -p and unborn branchesJeff King, Oct 25, 2013
  7. 1/2 add-interactive: handle unborn branch in patch modeJeff King, Oct 25, 2013
  8. 2/2 reset: pass real rev name to add--interactiveJeff King, Oct 25, 2013
  9. Junio C HamanoOct 25, 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.