From 883d60ec0e7d840aea811f4f38a882d7c1efbdb5 Mon Sep 17 00:00:00 2001 From: Adam Tao Date: Wed, 14 Jun 2023 16:18:29 +0800 Subject: [PATCH] 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 Signed-off-by: Adam Tao --- autoload/gitgutter/diff.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index a3edb12..9e016a4 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -407,7 +407,13 @@ function! s:write_buffer(bufnr, file) endif if getbufvar(a:bufnr, '&fileformat') ==# 'dos' - call map(bufcontents, 'v:val."\r"') + 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')