mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 04:23:46 -05:00
Set diff base when viewing file versions with Fugitive
When you look at previous versions of a file, e.g. with Fugitive's :0Gclog, gitgutter will set the diff base to the current version's parent so that diff markers appear as expected. Thannks to @rcreasi for the idea and initial implementation.
This commit is contained in:
@@ -190,8 +190,20 @@ function! s:restore_shell() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#set_diff_base_if_fugitive(bufnr)
|
||||
let p = resolve(expand('#'.a:bufnr.':p'))
|
||||
let ml = matchlist(p, '\v^fugitive:/.*/(\x{40,})/')
|
||||
if !empty(ml) && !empty(ml[1])
|
||||
let g:gitgutter_diff_base = ml[1].'^'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:abs_path(bufnr, shellesc)
|
||||
let p = resolve(expand('#'.a:bufnr.':p'))
|
||||
|
||||
" Remove extra parts from fugitive's filepaths
|
||||
let p = substitute(substitute(p, '^fugitive:', '', ''), '\v\.git/\x{40,}/', '', '')
|
||||
|
||||
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user