Support discarding multiple changes in visual mode

Closes https://github.com/tpope/vim-fugitive/issues/944
This commit is contained in:
Tim Pope 2019-08-18 01:45:33 -04:00
parent e69a3ea21a
commit 25581bf775

View File

@ -3004,15 +3004,18 @@ function! s:StageApply(info, reverse, extra) abort
endfunction
function! s:StageDelete(lnum1, lnum2, count) abort
let info = get(s:Selection(a:lnum1, a:lnum2), 0, {'filename': ''})
if empty(info.filename)
return ''
let restore = []
let err = ''
try
for info in s:Selection(a:lnum1, a:lnum2)
if empty(info.paths)
continue
endif
let hash = s:TreeChomp('hash-object', '-w', '--', info.paths[0])
try
if empty(hash)
return ''
elseif info.patch
continue
endif
if info.patch
call s:StageApply(info, 1, info.section ==# 'Staged' ? ['--index'] : [])
elseif info.status ==# '?'
call s:TreeChomp('clean', '-f', '--', info.paths[0])
@ -3032,14 +3035,17 @@ function! s:StageDelete(lnum1, lnum2, count) abort
else
call s:TreeChomp('checkout', 'HEAD^{}', '--', info.paths[0])
endif
call add(restore, ':Gsplit ' . s:fnameescape(info.relative[0]) . '|Gread ' . hash[0:6])
endfor
catch /^fugitive:/
return 'echoerr ' . string(v:exception)
let err = '|echoerr ' . string(v:exception)
endtry
if empty(restore)
return err[1:-1]
endif
exe s:ReloadStatus()
call s:StageReveal()
let @@ = hash
return 'checktime|redraw|echomsg ' .
\ string('To restore, :Gedit ' . info.relative[0] . '|Gread ' . hash[0:6])
return 'checktime|redraw|echomsg ' . string('To restore, ' . join(restore, '|')) . err
endfunction
function! s:StageIgnore(lnum1, lnum2, count) abort