GNU bug report logs -
#62731
29.0.60; diff-apply-hunk doesn't work for creating new files
Previous Next
Reported by: sbaugh <at> catern.com
Date: Sun, 9 Apr 2023 01:15:02 UTC
Severity: normal
Found in version 29.0.60
Done: Dmitry Gutov <dmitry <at> gutov.dev>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Hi!
On 09/04/2023 04:14, sbaugh <at> catern.com wrote:
> 1. emacs -Q
> 2. Put the following content in a diff-mode buffer:
> diff --git a/foo b/foo
> new file mode 100644
> --- /dev/null
> +++ b/foo
> @@ -0,0 +1,1 @@
> +content
> 3. C-c C-a
>
> Expected behavior: A file called "foo" with content "content" is
> created.
>
> 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.
It makes some assumptions, though, (such as that default-directory fits
the file names in the diff, which is normal for vc diffs but maybe not
others), so some testing would be welcome, especially from people who
deal with diffs produced otherwise.
[diff-find-file-name-new.diff (text/x-patch, attachment)]
This bug report was last modified 217 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.