mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 05:43:52 -05:00
Support FileWriteCmd
This correctly requires a bang to write a partial file, but the error message is E212 rather than the more appropriate E140.
This commit is contained in:
@@ -2822,15 +2822,15 @@ function! fugitive#FileReadCmd(...) abort
|
|||||||
return line . 'read !' . escape(cmd, '!#%')
|
return line . 'read !' . escape(cmd, '!#%')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#BufWriteCmd(...) abort
|
function! fugitive#FileWriteCmd(...) abort
|
||||||
let tmp = tempname()
|
let tmp = tempname()
|
||||||
let amatch = a:0 ? a:1 : expand('<amatch>')
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
||||||
try
|
try
|
||||||
let [dir, commit, file] = s:DirCommitFile(amatch)
|
let [dir, commit, file] = s:DirCommitFile(amatch)
|
||||||
if commit !~# '^[0-3]$'
|
if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$'))
|
||||||
return 'noautocmd write' . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch)
|
return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch)
|
||||||
endif
|
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 sha1 = readfile(tmp)[0]
|
||||||
let old_mode = matchstr(system(fugitive#Prepare(dir, 'ls-files', '--stage', file[1:-1])), '^\d\+')
|
let old_mode = matchstr(system(fugitive#Prepare(dir, 'ls-files', '--stage', file[1:-1])), '^\d\+')
|
||||||
if old_mode == ''
|
if old_mode == ''
|
||||||
@@ -2945,6 +2945,10 @@ function! fugitive#BufReadCmd(...) abort
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#BufWriteCmd(...) abort
|
||||||
|
return call('fugitive#FileWriteCmd', a:000)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#SourceCmd(...) abort
|
function! fugitive#SourceCmd(...) abort
|
||||||
let amatch = a:0 ? a:1 : expand('<amatch>')
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
||||||
let temp = s:BlobTemp(amatch)
|
let temp = s:BlobTemp(amatch)
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ augroup fugitive
|
|||||||
autocmd BufReadCmd fugitive://*//* exe fugitive#BufReadCmd()
|
autocmd BufReadCmd fugitive://*//* exe fugitive#BufReadCmd()
|
||||||
autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteCmd()
|
autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteCmd()
|
||||||
autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd()
|
autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd()
|
||||||
|
autocmd FileWriteCmd fugitive://*//[0-3]/* exe fugitive#FileWriteCmd()
|
||||||
autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd()
|
autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd()
|
||||||
|
|
||||||
autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
|
autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
|
||||||
|
|||||||
Reference in New Issue
Block a user