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,42 +3004,48 @@ 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 ''
endif
let hash = s:TreeChomp('hash-object', '-w', '--', info.paths[0])
try try
if empty(hash) for info in s:Selection(a:lnum1, a:lnum2)
return '' if empty(info.paths)
elseif info.patch continue
call s:StageApply(info, 1, info.section ==# 'Staged' ? ['--index'] : []) endif
elseif info.status ==# '?' let hash = s:TreeChomp('hash-object', '-w', '--', info.paths[0])
call s:TreeChomp('clean', '-f', '--', info.paths[0]) if empty(hash)
elseif a:count == 2 continue
call s:TreeChomp('checkout', '--ours', '--', info.paths[0]) endif
elseif a:count == 3 if info.patch
call s:TreeChomp('checkout', '--theirs', '--', info.paths[0]) call s:StageApply(info, 1, info.section ==# 'Staged' ? ['--index'] : [])
elseif info.status =~# '[ADU]' && elseif info.status ==# '?'
\ get(b:fugitive_status[info.section ==# 'Staged' ? 'Unstaged' : 'Staged'], info.filename, '') =~# '[AU]' call s:TreeChomp('clean', '-f', '--', info.paths[0])
call s:TreeChomp('checkout', info.section ==# 'Staged' ? '--ours' : '--theirs', '--', info.paths[0]) elseif a:count == 2
elseif info.status ==# 'U' call s:TreeChomp('checkout', '--ours', '--', info.paths[0])
call s:TreeChomp('rm', '--', info.paths[0]) elseif a:count == 3
elseif info.status ==# 'A' call s:TreeChomp('checkout', '--theirs', '--', info.paths[0])
call s:TreeChomp('rm', '-f', '--', info.paths[0]) elseif info.status =~# '[ADU]' &&
elseif info.section ==# 'Unstaged' \ get(b:fugitive_status[info.section ==# 'Staged' ? 'Unstaged' : 'Staged'], info.filename, '') =~# '[AU]'
call s:TreeChomp('checkout', '--', info.paths[0]) call s:TreeChomp('checkout', info.section ==# 'Staged' ? '--ours' : '--theirs', '--', info.paths[0])
else elseif info.status ==# 'U'
call s:TreeChomp('checkout', 'HEAD^{}', '--', info.paths[0]) call s:TreeChomp('rm', '--', info.paths[0])
endif elseif info.status ==# 'A'
call s:TreeChomp('rm', '-f', '--', info.paths[0])
elseif info.section ==# 'Unstaged'
call s:TreeChomp('checkout', '--', info.paths[0])
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:/ 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