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

From: Junio C Hamano <[email-masked]>
Date: Tue, 06 May 2014 14:12:52 -0700

Nathan Collins <[email-masked]> 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.