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

Re: [BUG?] Patches created with 'diff.noprefix=true' don't 'git apply'.

From
Junio C Hamano <gitster@pobox.com>
Date
May 7, 2014, 18:42 UTC
Message-ID
<xmqqzjita0sn.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAO8RVveF6Oh0mqqyiVRHmnqQ+vXX7riDW_=zn0g=t88cQjCVrg@mail.gmail.com>
Nathan Collins <nathan.collins@gmail.com> writes:
Show 6 quoted lines
> More concretely, what I had in mind was that if 'diff.noprefix=true'
> is set in the user's config, and the patch is in '-p0' format, then
> Git could suggest to the user that the 'diff.noprefix' setting *might*
> be causing them to generate '-p0' patches. If the user had in fact not
> generated the patch themselves, then they could safely ignore the
> suggestion.

Issuing a suggestion that can be ignored too often sounds like crying wolf to train users to ignore all other more useful suggestions, so I would advise to be very cautious before doing so. If you cannot come up with a way to make the heuristics very sure and foolproof, I do not think it would help more than it hurt.

One possibility I considered briefly before discarding it was to see if the input is coming from a pipe *and* these configuration is set.

> But this may just be an overcomplicated solution to my and others'
> misuse of the 'diff.noprefix' option; see below.
>
>> So that is not workable.
Yes.
Show 11 quoted lines
>> However, Before issuing this error message
>>
>>>   git -c diff.noprefix=true diff HEAD~ | git apply --reverse
>>>   error: Data/Function/Decorator/Memoizer/Unsafe.hs: No such file or directory
>>
>> we _could_ check that there is Data/ directory in the target tree
>> the patch is being applied and suggest to:
>
> To clarify, the actual path was
>
>   src/Data/Function/Decorator/Memoizer/Unsafe.hs

Yeah, and I meant to suggest checking that path is plausible. It would not help when adding a new file, but we can issue the original error message and that is perfectly readable, so catching only paths that are modified or deleted and suggesting -p$n is still making things better.

> 1. 'git apply' doesn't give a very helpful error message when the
> patch does not apply due to not being in '-p1' format.

That "Data/Function/..." path in the error message is helpful enough, once you learn that -p$n strips the leading directory and that -p1 is the default. For new people, however, -p1 being the default might be unexpected, but the learning curve is not that steep, I would think. So this is a one-time thing.

Show 5 quoted lines
> 2. the 'diff.noprefix=true' option is used for two unrelated things in
> practice. One of them is related to diffing -- namely, making Git
> generate '-p0' patches -- and the other is unrelated to diffing --
> namely, users want file names that can be easily copied with
> double-click.

I do not share this observation, as I never double-click. I let my shell to complete instead ;-)

Show 11 quoted lines
> For (2), the solution may be to add a separate
> 'diff.add-clickable-paths' option (probably there is a better name?
> 'diff.add-copyable-paths'? ...),...
> ...
> Concretely, if 'diff.add-clickable-paths' is set, then instead of e.g.
>
>   diff --git a/src/Data/Function/Decorator/Memoizer/Unsafe.hs
> b/src/Data/Function/Decorator/Memoizer
>   index 3ef17da..a0586d3 100644
>   --- a/src/Data/Function/Decorator/Memoizer/Unsafe.hs
>   +++ b/src/Data/Function/Decorator/Memoizer/Unsafe.hs
If you do something along that line, perhaps
	Index: src/Data/Function/Decorator/Memoizer/Unsafe.hs
        diff --git a/src/Data/Function/Decorator/Memoizer/Unsafe.hs ...
        index 3ef17da..a0586d3 100644
        --- a/src/Data/Function/Decorator/Memoizer/Unsafe.hs
        +++ b/src/Data/Function/Decorator/Memoizer/Unsafe.hs
to imitate what "cvs diff" does may be more familar to people.
What would you propose to make clickable in a renaming diff, though?
        
Previous: Nathan CollinsNext: Nathan Collins
Message 9 of 13 in “[BUG?] Patches created with 'diff.noprefix=true' don't 'git apply'.”
  1. Nathan CollinsMay 1, 2014
  2. Jonathan NiederMay 1, 2014
  3. Nathan CollinsMay 6, 2014
  4. Jonathan NiederMay 6, 2014
  5. Junio C HamanoMay 6, 2014
  6. Nathan CollinsMay 6, 2014
  7. Junio C HamanoMay 6, 2014
  8. Nathan CollinsMay 7, 2014
  9. Junio C HamanoMay 7, 2014
  10. Nathan CollinsMay 7, 2014
  11. Nathan CollinsMay 8, 2014
  12. Nathan CollinsMay 8, 2014
  13. Junio C HamanoMay 8, 2014

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.