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