From 061a81f247538aeb61e165e1551355f289d52f63 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 21 Jun 2014 10:05:46 -0400 Subject: [PATCH] Provide checkout/unlink on U in :Gstatus Closes #97. --- plugin/fugitive.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index f537ab4..bcf88cd 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -777,6 +777,28 @@ function! s:StageReloadSeek(target,lnum1,lnum2) abort call search('^#\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\V'.jump.'\%( ([^()[:digit:]]\+)\)\=\$','W') endfunction +function! s:StageUndo() abort + let [filename, section] = s:stage_info(line('.')) + if empty(filename) + return '' + endif + let repo = s:repo() + let hash = repo.git_chomp('hash-object', '-w', filename) + if !empty(hash) + if section ==# 'untracked' + call delete(s:repo().tree(filename)) + elseif section ==# 'unstaged' + call repo.get_chomp('checkout', '--', filename) + else + call repo.get_chomp('checkout', 'HEAD', '--', filename) + endif + call s:StageReloadSeek(filename, line('.'), line('.')) + let @" = hash + return 'checktime|redraw|echomsg ' . + \ string('To restore, :Git cat-file blob '.hash[0:6].' > '.filename) + endif +endfunction + function! s:StageDiff(diff) abort let [filename, section] = s:stage_info(line('.')) if filename ==# '' && section ==# 'staged' @@ -2158,6 +2180,7 @@ function! s:BufReadIndex() abort nnoremap q :if bufnr('$') == 1quitelsebdeleteendif nnoremap r :edit nnoremap R :edit + nnoremap U :execute StageUndo() nnoremap g? :help fugitive-:Gstatus nnoremap :help fugitive-:Gstatus catch /^fugitive:/