Fix commit maps while accommodating bad modelines

We need modifiable off for the maps to kick in, but we need to turn it
back off before the doautocmd or else it will throw an error if the
modeline modifies the buffer with an option like fileencoding, which you
should never do, stop doing it.
This commit is contained in:
Tim Pope
2019-01-05 01:43:59 -05:00
parent b88d064ac4
commit b1a993964b

View File

@@ -1718,16 +1718,17 @@ function! fugitive#BufReadCmd(...) abort
if &bufhidden ==# ''
setlocal bufhidden=delete
endif
let &modifiable = modifiable
if b:fugitive_type !=# 'blob'
setlocal filetype=git foldmethod=syntax
nnoremap <buffer> <silent> a :<C-U>let b:fugitive_display_format += v:count1<Bar>exe fugitive#BufReadCmd(@%)<CR>
nnoremap <buffer> <silent> i :<C-U>let b:fugitive_display_format -= v:count1<Bar>exe fugitive#BufReadCmd(@%)<CR>
else
let &modifiable = modifiable
call fugitive#MapJumps()
endif
endtry
setlocal modifiable
return 'silent doautocmd' . (v:version >= 704 ? ' <nomodeline>' : '') .
\ ' BufReadPost' . (modifiable ? '' : '|setl nomodifiable')
catch /^fugitive:/