From 1d422b9f98194e38bc56e54192c9bc66d95c21f1 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Sat, 15 Dec 2018 14:55:14 +0000 Subject: [PATCH] Revert to non-binary writefile() for writing buffer. The previous commit switched use of writefile() to binary mode so that we could prevent a newline being added to a completely empty buffer. Evidently, however, binary mode has side effects (see #567) so this commit returns to non-binary mode - with a simpler fix for completely empty files. Unfortunately this implementation does not work for noeol files - see the failing test - because writefile() does not take account of 'nofixeol' (unlike :write). This is suboptimal but acceptable because noeol files are not be encountered often. See #567. --- autoload/gitgutter/diff.vim | 12 ++++-------- test/test_gitgutter.vim | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index e1bd5a3..b270db7 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -375,14 +375,10 @@ function! s:write_buffer(bufnr, file) let bufcontents = getbufline(a:bufnr, 1, '$') if bufcontents == [''] && line2byte(1) == -1 - " Special case: empty buffer; do not write an empty line in this case. + " Special case: completely empty buffer. " A nearly empty buffer of only a newline has line2byte(1) == 1. - else - if getbufvar(a:bufnr, '&endofline') - \ || (!getbufvar(a:bufnr, '&binary') - \ && (!exists('+fixendofline') || getbufvar(a:bufnr, '&fixendofline'))) - call add(bufcontents, '') - endif + call writefile([], a:file) + return endif if getbufvar(a:bufnr, '&fileformat') ==# 'dos' @@ -398,7 +394,7 @@ function! s:write_buffer(bufnr, file) let bufcontents[0]=''.bufcontents[0] endif - call writefile(bufcontents, a:file, 'b') + call writefile(bufcontents, a:file) endfunction diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index 2f0c27c..855eca3 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -669,7 +669,7 @@ function Test_empty_file() " 1 line file without newline " Vim will force a newline unless we tell it not to. - call system('echo -n "a" > oneline.txt && git add oneline.txt') + call system('echo -n a > oneline.txt && git add oneline.txt') set noeol nofixeol edit! oneline.txt