:Gdiff does a three-way during a conflict

This commit is contained in:
Tim Pope 2009-10-14 23:26:10 -04:00
parent 04b845a4e9
commit b65030cd3b
2 changed files with 26 additions and 9 deletions

View File

@ -92,9 +92,12 @@ that are part of Git repositories).
the index. the index.
*fugitive-:Gdiff* *fugitive-:Gdiff*
:Gdiff [revision] Perform a |vimdiff| the current file against the index :Gdiff [revision] Perform a |vimdiff| against the current file in the
or the given revision. Use |do| and |dp| and write to given revision. With no argument, the version in the
the index file to simulate git add -p. 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* *fugitive-:Gmove*
:Gmove {destination} Wrapper around git-mv that renames the buffer :Gmove {destination} Wrapper around git-mv that renames the buffer

View File

@ -649,29 +649,43 @@ endfunction
call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gdiff :execute s:Diff(<f-args>)") 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 function! s:Diff(...) abort
if exists(':DiffGitCached') if exists(':DiffGitCached')
return '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 elseif a:0
if a:1 ==# '' if a:1 ==# ''
return '' return ''
elseif a:1 == ':' || a:1 == '/' elseif a:1 ==# '/'
let file = s:buffer().path(a:1) let file = s:buffer().path('/')
elseif a:1 ==# ':'
let file = s:buffer().path(':0:')
else else
let file = s:buffer().expand(a:1) let file = s:buffer().expand(a:1)
endif endif
if file !~ ':' && file !~ '^/' if file !~ ':' && file !~ '^/'
let file = file.s:buffer().path(':') let file = file.s:buffer().path(':0:')
endif endif
else else
let file = s:buffer().path(s:buffer().commit() == '' ? ':' : '/') let file = s:buffer().path(s:buffer().commit() == '' ? ':0:' : '/')
endif endif
try try
vsplit `=fugitive#buffer().repo().translate(file)` vsplit `=fugitive#buffer().repo().translate(file)`
let b:fugitive_restore = 'diffoff!'
diffthis diffthis
wincmd p wincmd p
let b:fugitive_restore = 'diffoff!'
diffthis diffthis
return '' return ''
catch /^fugitive:/ catch /^fugitive:/