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:
Andy Stewart
2013-02-21 10:38:29 +01:00
parent 5fae75637c
commit cda4597459

View File

@@ -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