diff --git a/doc/fugitive.txt b/doc/fugitive.txt index d4790b4..94a0e11 100644 --- 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 index 1129bfe..2f0e772 100644 --- 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()") +augroup fugitive_diff + autocmd BufWinLeave * if winnr('$') == 2 && &diff && getbufvar(+expand(''), 'git_dir') !=# '' | diffoff! | endif + autocmd BufWinEnter * if winnr('$') == 1 && &diff && getbufvar(+expand(''), '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:/