diff --git a/README.mkd b/README.mkd index 0c21f3c..bb39d14 100644 --- a/README.mkd +++ b/README.mkd @@ -399,6 +399,8 @@ By default buffers are diffed against the index. However you can diff against a let g:gitgutter_diff_base = '' ``` +If you are looking at a previous version of a file with Fugitive (e.g. via `:0Gclog`), gitgutter sets the diff base to the parent of the current revision. + This setting is ignored when the diffs are relative to the working tree. diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index adf5d9e..4e83d4d 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -33,6 +33,8 @@ function! gitgutter#process_buffer(bufnr, force) abort return endif + call gitgutter#utility#set_diff_base_if_fugitive(a:bufnr) + if a:force || s:has_fresh_changes(a:bufnr) let diff = 'NOT SET' diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 609f5ec..ba4974a 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -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 diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index 1f52989..074f334 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -366,6 +366,9 @@ a revision instead. For example: let g:gitgutter_diff_base = '' < +If you are looking at a previous version of a file with Fugitive (e.g. +via :0Gclog), gitgutter sets the diff base to the parent of the current revision. + This setting is ignore when the diff is relative to the working tree (|g:gitgutter_diff_relative_to|).