From 3fc2cec5e43f6c16e2dc1f28dee708daf08ce856 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Mon, 18 Jun 2018 19:26:50 +0300 Subject: [PATCH] Export a Git diff command GV current shows various Git diffs (unlike vim-fugitive, which only shows database objects), so it makes sense to export this functionality, say, for viewing the diff against HEAD or the index. For instance: :call gv#diff("HEAD") :call gv#diff("--cached", "HEAD") --- plugin/gv.vim | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index 0371528..2068c73 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -34,6 +34,12 @@ function! gv#sha(...) return matchstr(get(a:000, 0, getline('.')), s:begin.'\zs[a-f0-9]\+') endfunction +function! gv#diff(...) + let l:list = deepcopy(a:000) + call insert(l:list, "diff", 0) + call s:open_direct('diff', call(fugitive#repo().git_command, l:list)) +endfunction + function! s:move(flag) let [l, c] = searchpos(s:begin, a:flag) return l ? printf('%dG%d|', l, c) : '' @@ -95,20 +101,27 @@ endfunction function! s:open(visual, ...) let [type, target] = s:type(a:visual) + if a:0 == 1 + return s:open_direct(type, target, a:1) + else + return s:open_direct(type, target) + endif +endfunction - if empty(type) +function! s:open_direct(type, target, ...) + if empty(a:type) return s:shrug() - elseif type == 'link' - return s:browse(target) + elseif a:type == 'link' + return s:browse(a:target) endif call s:split(a:0) - if type == 'commit' - execute 'e' escape(target, ' ') + if a:type == 'commit' + execute 'e' escape(a:target, ' ') nnoremap gb :Gbrowse - elseif type == 'diff' + elseif a:type == 'diff' call s:scratch() - call s:fill(target) + call s:fill(a:target) setf diff endif nnoremap q :close