From 5485c37b38da4e4b29f55177357316888e419465 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Mon, 27 Jan 2014 14:51:19 +0100 Subject: [PATCH] Fix bug in realtime diff of non-current buffer. This bug meant that a realtime diff of a buffer which wasn't the current one -- which happens during GitGutterAll() -- diffed the staged version of the buffer against the current buffer's contents instead of the buffer's contents. --- autoload/diff.vim | 10 +--------- autoload/utility.vim | 11 +++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/autoload/diff.vim b/autoload/diff.vim index 554e3e1..29b88ba 100644 --- a/autoload/diff.vim +++ b/autoload/diff.vim @@ -25,15 +25,7 @@ function! diff#run_diff(realtime, use_external_grep) let cmd = utility#escape(cmd) if a:realtime - if &fileformat ==# "dos" - let eol = "\r\n" - elseif &fileformat ==# "mac" - let eol = "\r" - else - let eol = "\n" - endif - let buffer_contents = join(getline(1, '$'), eol) . eol - let diff = system(utility#command_in_directory_of_file(cmd), buffer_contents) + let diff = system(utility#command_in_directory_of_file(cmd), utility#buffer_contents()) else let diff = system(utility#command_in_directory_of_file(cmd)) endif diff --git a/autoload/utility.vim b/autoload/utility.vim index 8a67b4a..110c9dc 100644 --- a/autoload/utility.vim +++ b/autoload/utility.vim @@ -36,6 +36,17 @@ function! utility#save_last_seen_change(file) call setbufvar(a:file, 'gitgutter_last_tick', getbufvar(a:file, 'changedtick')) endfunction +function! utility#buffer_contents() + if &fileformat ==# "dos" + let eol = "\r\n" + elseif &fileformat ==# "mac" + let eol = "\r" + else + let eol = "\n" + endif + return join(getbufline(s:file, 1, '$'), eol) . eol +endfunction + " https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17 function! utility#escape(str) if &shellxquote ==# '"'