> From: Juri Linkov <j...@linkov.net> > Cc: Tomas Nordin <tom...@posteo.net>, Dmitry Gutov <dmi...@gutov.dev>, > 72...@debbugs.gnu.org > Date: Mon, 19 Aug 2024 19:49:05 +0300 > > >> To reproduce: > >> > >> $ mkdir apply > >> $ cd apply > >> $ echo "first line of code" > example.file > >> $ git init > >> $ git add . > >> $ git commit -m 'init' > >> $ echo "last line of code" >> example.file > >> $ emacs -Q example.file > >> > >> C-x v = > >> n > >> C-c C-a > >> > >> The hunk is applied in the source buffer. > > > > Juri and Dmitry, any comments or suggestions? > > I don't know why it fails at the end, so I tried to debug 'diff-apply-hunk', > and found that the problem is in these lines of 'diff-find-source-location': > > ;; FIXME: Check for case where both OLD and NEW are found. > (pos (or (diff-find-text (car old)) > > When the hunk is at the beginning/end of the diff buffer, > then it misses the top/bottom part of the context, > so 'diff-find-text' wrongly matches it because it fails > to see any changes in it due to insufficient context, > and returns switched=nil. > > A possible solution would be to add a condition to detect the case > when the hunk is at the beginning/end of the diff buffer.
Thanks. Would anyone like to submit a patch along these lines?