diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 8a51752..6938eb3 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1283,7 +1283,7 @@ endfunction call s:add_methods('buffer',['compare_age']) -function! s:Diff(bang,...) abort +function! s:Diff(bang,...) let split = a:bang ? 'split' : 'vsplit' if exists(':DiffGitCached') return 'DiffGitCached' @@ -1930,10 +1930,13 @@ function! s:BufReadIndexFile() try let b:fugitive_type = 'blob' let b:git_dir = s:repo().dir() - call s:ReplaceCmd(s:repo().git_command('cat-file','blob',s:buffer().sha1())) - if &bufhidden ==# '' - setlocal bufhidden=delete - endif + try + call s:ReplaceCmd(s:repo().git_command('cat-file','blob',s:buffer().sha1())) + finally + if &bufhidden ==# '' + setlocal bufhidden=delete + endif + endtry return '' catch /^fugitive: rev-parse/ silent exe 'doau BufNewFile '.s:fnameescape(bufname('')) @@ -1998,52 +2001,55 @@ function! s:BufReadObject() silent %delete setlocal endofline - if b:fugitive_type == 'tree' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('ls-tree',hash)) - else - call s:ReplaceCmd(s:repo().git_command('show','--no-color',hash)) - endif - elseif b:fugitive_type == 'tag' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - else - call s:ReplaceCmd(s:repo().git_command('cat-file','-p',hash)) - endif - elseif b:fugitive_type == 'commit' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - else - call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash)) - call search('^parent ') - if getline('.') ==# 'parent ' - silent delete_ + try + if b:fugitive_type == 'tree' + let b:fugitive_display_format = b:fugitive_display_format % 2 + if b:fugitive_display_format + call s:ReplaceCmd(s:repo().git_command('ls-tree',hash)) else - silent s/\%(^parent\)\@\)\=$','W',line('.')+3) - silent delete_ - end - 1 + elseif b:fugitive_type == 'tag' + let b:fugitive_display_format = b:fugitive_display_format % 2 + if b:fugitive_display_format + call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) + else + call s:ReplaceCmd(s:repo().git_command('cat-file','-p',hash)) + endif + elseif b:fugitive_type == 'commit' + let b:fugitive_display_format = b:fugitive_display_format % 2 + if b:fugitive_display_format + call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) + else + call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash)) + call search('^parent ') + if getline('.') ==# 'parent ' + silent delete_ + else + silent s/\%(^parent\)\@\)\=$','W',line('.')+3) + silent delete_ + end + 1 + endif + elseif b:fugitive_type ==# 'blob' + call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) endif - elseif b:fugitive_type ==# 'blob' - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - endif - call setpos('.',pos) - setlocal ro noma nomod - if &bufhidden ==# '' - setlocal bufhidden=delete - endif - if b:fugitive_type !=# 'blob' - set filetype=git - nnoremap a :let b:fugitive_display_format += v:count1exe BufReadObject() - nnoremap i :let b:fugitive_display_format -= v:count1exe BufReadObject() - else - call s:JumpInit() - endif + finally + call setpos('.',pos) + setlocal ro noma nomod + if &bufhidden ==# '' + setlocal bufhidden=delete + endif + if b:fugitive_type !=# 'blob' + set filetype=git + nnoremap a :let b:fugitive_display_format += v:count1exe BufReadObject() + nnoremap i :let b:fugitive_display_format -= v:count1exe BufReadObject() + else + call s:JumpInit() + endif + endtry return '' catch /^fugitive:/