fix(diff): Wrong diff if dos format combines with noeol

If fileformat is dos and eol is not set, then a '\r' (but without '\n')
will be written to the last line of temporary buffer file, which will
confuse git and make git think all lines are modified. Fix it by adding
'r' to all lines except the last one if fileformat is dos and eol is not
set.

Suggested-by: Andy Stewart <boss@airbladesoftware.com>
Signed-off-by: Adam Tao <tcx4c70@gmail.com>
This commit is contained in:
Adam Tao
2023-06-14 16:18:29 +08:00
committed by Andy Stewart
parent e2056e54c5
commit 883d60ec0e

View File

@@ -407,7 +407,13 @@ function! s:write_buffer(bufnr, file)
endif
if getbufvar(a:bufnr, '&fileformat') ==# 'dos'
if getbufvar(a:bufnr, '&endofline')
call map(bufcontents, 'v:val."\r"')
else
for i in range(len(bufcontents) - 1)
let bufcontents[i] = bufcontents[i] . "\r"
endfor
endif
endif
if getbufvar(a:bufnr, '&endofline')