From d137753182b7f10986e4454d76c49e8477b8ef2c Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Mon, 12 Feb 2018 16:19:01 +0000 Subject: [PATCH] Handle &write option being off (e.g. vim -m FILE). See #407. --- autoload/gitgutter/diff.vim | 5 +++++ test/test_gitgutter.vim | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 4544cde..710b611 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -289,6 +289,9 @@ endfunction function! s:write_buffer(bufnr, file) + let _write = &write + set write + " Write specified buffer (which may not be the current buffer) to buff_file. " There doesn't seem to be a clean way to write a buffer that isn't the current " to a file; we have to switch to it, write it, then switch back. @@ -309,6 +312,8 @@ function! s:write_buffer(bufnr, file) call setpos("']", op_mark_end) execute 'noautocmd buffer' current_buffer + + let &write = _write endfunction diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index b5d69ec..2c820cd 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -424,3 +424,16 @@ function Test_undo_nearby_hunk() call assert_equal(expected, s:git_diff()) endfunction + + +function Test_write_option() + set nowrite + + normal ggo* + doautocmd CursorHold + + let expected = ["line=2 id=3000 name=GitGutterLineAdded"] + call assert_equal(expected, s:signs('fixture.txt')) + + set write +endfunction