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 6, 2014, 21:12 UTC
Message-ID
<xmqqbnvaehm3.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAO8RVvfHVBG6QZ5M1DJK4kOX8GMDrvEw4_L=LsEc4G6E0pP7ug@mail.gmail.com>
Nathan Collins <nathan.collins@gmail.com> writes:
> But 'git apply' could be much more helpful than 'patch' even, since
> the presence or absence of the 'a/' and 'b/' prefixes in the patch,
> and the 'diff.noprefix' setting, give Git enough info to be very
> helpful to the user.

The prefix would be unreliable as the generator may be using the mnemonicprefix option to use i/ and w/ prefixes. Worse yet, the configuration variables are for people who generated the diff you are feeding "git apply", and there is nothing that tells "apply" that the patch is generated with _your_ setting.

So that is not workable.
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:

 * "use -p0", if noprefix, which I agree with Jonathan is an insane
   thing to use by default, is common enough; or
 * "use different setting for -p$n", if noprefix is not common.

in the error message. Extra computation necessary to do so would happen only in the error codepath, and we wouldn't mind spending some cycles if they help the end user.

Previous: Nathan CollinsNext: Nathan Collins
Message 7 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.