Subject: Re: bug#62731: 29.0.60; diff-apply-hunk doesn't work for creating new files

From: Eli Zaretskii <[email-masked]>
Date: Wed, 02 Oct 2024 09:58:53 +0300

> Date: Wed, 2 Oct 2024 03:41:05 +0300
> From: Dmitry Gutov <[email-masked]>
> 
> > Observed behavior: diff-mode prompts for the location of "b/foo", and
> > doesn't allow specifying the location as a non-existent file, meaning
> > the file can't actaully be created.
> 
> This is annoying indeed.
> 
> The attached patch should handle this:
> 
> * When OLD equals to /dev/null, allow reading non-existing file name.
> * When NEW starts with b/ or /a, slice that off if such dir does not exist.
> * Bonus: when the diff is applied in reverse, the checked file names are 
> switched. That helps undo deletions as well. Or renames.

I think Git uses other prefixes as well (something like i/ and r/,
perhaps?)  And relying on b/ being an existing directory can cause
false positives.  How about relying on the "--git" part in the
"diff --git" header instead, and in the Git case _always_ removing one
leading directory?  (And if this also happens with Hg, include that in
the test as well.)

Also, what about the opposite case, when NEW is /dev/null? does that
work correctly?

Thanks.