From cda45974590d752dff466065a6fe61c3e703a541 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 21 Feb 2013 10:38:29 +0100 Subject: [PATCH] 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. --- plugin/gitgutter.vim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 84a01c1..e0012db 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -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