mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 12:33:47 -05:00
Always use path relative to repo root with git-show.
More recent versions of git support paths relative to current directory. But for maximum compatibility we need to use paths relative to the file's repo's root.
This commit is contained in:
@@ -7,7 +7,7 @@ function! diff#run_diff(realtime, use_external_grep)
|
|||||||
let cmd = 'git ls-files --error-unmatch ' . shellescape(utility#file()) . ' && ('
|
let cmd = 'git ls-files --error-unmatch ' . shellescape(utility#file()) . ' && ('
|
||||||
|
|
||||||
if a:realtime
|
if a:realtime
|
||||||
let blob_name = ':./' . fnamemodify(utility#file(),':t')
|
let blob_name = ':' . utility#file_relative_to_repo_root()
|
||||||
let blob_file = tempname()
|
let blob_file = tempname()
|
||||||
let cmd .= 'git show ' . blob_name . ' > ' . blob_file .
|
let cmd .= 'git show ' . blob_name . ' > ' . blob_file .
|
||||||
\ ' && diff -U0 ' . g:gitgutter_diff_args . ' ' . blob_file . ' - '
|
\ ' && diff -U0 ' . g:gitgutter_diff_args . ' ' . blob_file . ' - '
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ function! utility#is_active()
|
|||||||
return g:gitgutter_enabled && utility#exists_file()
|
return g:gitgutter_enabled && utility#exists_file()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! utility#slash()
|
||||||
|
return !exists("+shellslash") || &shellslash ? '/' : '\'
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! utility#current_file()
|
function! utility#current_file()
|
||||||
return expand('%:p')
|
return expand('%:p')
|
||||||
endfunction
|
endfunction
|
||||||
@@ -47,6 +51,16 @@ function! utility#buffer_contents()
|
|||||||
return join(getbufline(s:file, 1, '$'), eol) . eol
|
return join(getbufline(s:file, 1, '$'), eol) . eol
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! utility#file_relative_to_repo_root()
|
||||||
|
let repo_root_for_file = getbufvar(s:file, 'gitgutter_repo_root')
|
||||||
|
if empty(repo_root_for_file)
|
||||||
|
let dir = system(utility#command_in_directory_of_file('git rev-parse --show-toplevel'))
|
||||||
|
let repo_root_for_file = substitute(dir, '\n$', '', '') . utility#slash()
|
||||||
|
call setbufvar(s:file, 'gitgutter_repo_root', repo_root_for_file)
|
||||||
|
endif
|
||||||
|
return substitute(s:file, repo_root_for_file, '', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
" https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17
|
" https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17
|
||||||
function! utility#escape(str)
|
function! utility#escape(str)
|
||||||
if &shellxquote ==# '"'
|
if &shellxquote ==# '"'
|
||||||
|
|||||||
Reference in New Issue
Block a user