diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 731ce44..2d43ccf 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2822,15 +2822,15 @@ function! fugitive#FileReadCmd(...) abort return line . 'read !' . escape(cmd, '!#%') endfunction -function! fugitive#BufWriteCmd(...) abort +function! fugitive#FileWriteCmd(...) abort let tmp = tempname() let amatch = a:0 ? a:1 : expand('') try let [dir, commit, file] = s:DirCommitFile(amatch) - if commit !~# '^[0-3]$' - return 'noautocmd write' . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch) + if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$')) + return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch) endif - silent execute 'write !'.fugitive#Prepare(dir, 'hash-object', '-w', '--stdin').' > '.tmp + silent execute "'[,']write !".fugitive#Prepare(dir, 'hash-object', '-w', '--stdin').' > '.tmp let sha1 = readfile(tmp)[0] let old_mode = matchstr(system(fugitive#Prepare(dir, 'ls-files', '--stage', file[1:-1])), '^\d\+') if old_mode == '' @@ -2945,6 +2945,10 @@ function! fugitive#BufReadCmd(...) abort endtry endfunction +function! fugitive#BufWriteCmd(...) abort + return call('fugitive#FileWriteCmd', a:000) +endfunction + function! fugitive#SourceCmd(...) abort let amatch = a:0 ? a:1 : expand('') let temp = s:BlobTemp(amatch) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 56f0080..3b0e6ee 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -183,6 +183,7 @@ augroup fugitive autocmd BufReadCmd fugitive://*//* exe fugitive#BufReadCmd() autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteCmd() autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd() + autocmd FileWriteCmd fugitive://*//[0-3]/* exe fugitive#FileWriteCmd() autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd() autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))