Provide :Gdelete

Closes https://github.com/tpope/vim-fugitive/issues/804
This commit is contained in:
Tim Pope 2017-06-08 01:20:21 -04:00
parent 280bbdb6eb
commit be2ff98db5
3 changed files with 10 additions and 6 deletions

View File

@ -20,7 +20,7 @@ changed, or `o` to open it in a split. When you're done, use `:Gedit`
in the historic buffer to go back to the work tree version. in the historic buffer to go back to the work tree version.
`:Gmove` does a `git mv` on a file and simultaneously renames the `:Gmove` does a `git mv` on a file and simultaneously renames the
buffer. `:Gremove` does a `git rm` on a file and simultaneously deletes buffer. `:Gdelete` does a `git rm` on a file and simultaneously deletes
the buffer. the buffer.
Use `:Ggrep` to search the work tree (or any arbitrary commit) with Use `:Ggrep` to search the work tree (or any arbitrary commit) with

View File

@ -198,12 +198,15 @@ that are part of Git repositories).
directory except when started with a /, in which case directory except when started with a /, in which case
it is relative to the work tree. Add a ! to pass -f. it is relative to the work tree. Add a ! to pass -f.
*fugitive-:Gremove* *fugitive-:Gdelete*
:Gremove Wrapper around git-rm that deletes the buffer :Gdelete Wrapper around git-rm that deletes the buffer
afterward. When invoked in an index file, --cached is afterward. When invoked in an index file, --cached is
passed. Add a ! to pass -f and forcefully discard the passed. Add a ! to pass -f and forcefully discard the
buffer. buffer.
*fugitive-:Gremove*
:Gremove Like :Gdelete, but keep the (now empty) buffer around.
*fugitive-:Gblame* *fugitive-:Gblame*
:Gblame [flags] Run git-blame on the file and open the results in a :Gblame [flags] Run git-blame on the file and open the results in a
scroll bound vertical split. You can give any of scroll bound vertical split. You can give any of

View File

@ -1924,7 +1924,7 @@ function! s:MoveComplete(A,L,P) abort
endif endif
endfunction endfunction
function! s:Remove(force) abort function! s:Remove(after, force) abort
if s:buffer().commit() ==# '' if s:buffer().commit() ==# ''
let cmd = ['rm'] let cmd = ['rm']
elseif s:buffer().commit() ==# '0' elseif s:buffer().commit() ==# '0'
@ -1942,7 +1942,7 @@ function! s:Remove(force) abort
return 'echoerr '.string(v:errmsg) return 'echoerr '.string(v:errmsg)
else else
call fugitive#reload_status() call fugitive#reload_status()
return 'edit'.(a:force ? '!' : '') return a:after . (a:force ? '!' : '')
endif endif
endfunction endfunction
@ -1950,7 +1950,8 @@ augroup fugitive_remove
autocmd! autocmd!
autocmd User Fugitive if s:buffer().commit() =~# '^0\=$' | autocmd User Fugitive if s:buffer().commit() =~# '^0\=$' |
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:MoveComplete Gmove :execute s:Move(<bang>0,<q-args>)" | \ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:MoveComplete Gmove :execute s:Move(<bang>0,<q-args>)" |
\ exe "command! -buffer -bar -bang Gremove :execute s:Remove(<bang>0)" | \ exe "command! -buffer -bar -bang Gremove :execute s:Remove('edit',<bang>0)" |
\ exe "command! -buffer -bar -bang Gdelete :execute s:Remove('bdelete',<bang>0)" |
\ endif \ endif
augroup END augroup END