mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Run the git commands in each file's directory.
This allows vim-gitgutter to work whatever Vim's current directory is and whichever repos the files are in.
This commit is contained in:
@@ -33,13 +33,23 @@ function! s:current_file()
|
||||
return expand("%:p")
|
||||
endfunction
|
||||
|
||||
function! s:directory_of_current_file()
|
||||
return expand("%:p:h")
|
||||
endfunction
|
||||
|
||||
function! s:command_in_directory_of_current_file(cmd)
|
||||
return 'cd ' . s:directory_of_current_file() . ' && ' . a:cmd
|
||||
endfunction
|
||||
|
||||
function! s:is_in_a_git_repo()
|
||||
call system('git rev-parse > /dev/null 2>&1')
|
||||
let cmd = 'git rev-parse > /dev/null 2>&1'
|
||||
call system(s:command_in_directory_of_current_file(cmd))
|
||||
return !v:shell_error
|
||||
endfunction
|
||||
|
||||
function! s:is_tracked_by_git()
|
||||
call system('git ls-files --error-unmatch > /dev/null 2>&1 ' . shellescape(s:current_file()))
|
||||
let cmd = 'git ls-files --error-unmatch > /dev/null 2>&1 ' . shellescape(s:current_file())
|
||||
call system(s:command_in_directory_of_current_file(cmd))
|
||||
return !v:shell_error
|
||||
endfunction
|
||||
|
||||
@@ -49,7 +59,7 @@ endfunction
|
||||
|
||||
function! s:run_diff()
|
||||
let cmd = 'git diff --no-ext-diff -U0 ' . shellescape(s:current_file())
|
||||
let diff = system(cmd)
|
||||
let diff = system(s:command_in_directory_of_current_file(cmd))
|
||||
return diff
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user