commit b65030cd3b736b9b2f2591ca6e0cec2b9ad08c35 (tree)
parent 04b845a4e9d5a89f90d7f30b385d2fa7704d615e
Author: Tim Pope <code@tpope.net>
Date: Wed, 14 Oct 2009 23:26:10 -0400
:Gdiff does a three-way during a conflict
Diffstat:
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/doc/fugitive.txt b/doc/fugitive.txt
@@ -92,9 +92,12 @@ that are part of Git repositories).
the index.
*fugitive-:Gdiff*
-:Gdiff [revision] Perform a |vimdiff| the current file against the index
- or the given revision. Use |do| and |dp| and write to
- the index file to simulate git add -p.
+:Gdiff [revision] Perform a |vimdiff| against the current file in the
+ given revision. With no argument, the version in the
+ index is used (which means a three-way diff during a
+ merge conflict, making it a git mergetool
+ alternative). Use |do| and |dp| and write to the
+ index file to simulate git add -p.
*fugitive-:Gmove*
:Gmove {destination} Wrapper around git-mv that renames the buffer
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -649,29 +649,43 @@ endfunction
call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gdiff :execute s:Diff(<f-args>)")
+augroup fugitive_diff
+ autocmd BufWinLeave * if winnr('$') == 2 && &diff && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | diffoff! | endif
+ autocmd BufWinEnter * if winnr('$') == 1 && &diff && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | diffoff | endif
+augroup END
+
function! s:Diff(...) abort
if exists(':DiffGitCached')
return 'DiffGitCached'
+ elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# ''
+ leftabove vsplit `=fugitive#buffer().repo().translate(s:buffer().expand(':2'))`
+ diffthis
+ wincmd p
+ rightbelow vsplit `=fugitive#buffer().repo().translate(s:buffer().expand(':3'))`
+ diffthis
+ wincmd p
+ diffthis
+ return ''
elseif a:0
if a:1 ==# ''
return ''
- elseif a:1 == ':' || a:1 == '/'
- let file = s:buffer().path(a:1)
+ elseif a:1 ==# '/'
+ let file = s:buffer().path('/')
+ elseif a:1 ==# ':'
+ let file = s:buffer().path(':0:')
else
let file = s:buffer().expand(a:1)
endif
if file !~ ':' && file !~ '^/'
- let file = file.s:buffer().path(':')
+ let file = file.s:buffer().path(':0:')
endif
else
- let file = s:buffer().path(s:buffer().commit() == '' ? ':' : '/')
+ let file = s:buffer().path(s:buffer().commit() == '' ? ':0:' : '/')
endif
try
vsplit `=fugitive#buffer().repo().translate(file)`
- let b:fugitive_restore = 'diffoff!'
diffthis
wincmd p
- let b:fugitive_restore = 'diffoff!'
diffthis
return ''
catch /^fugitive:/