diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 44246f7..1cbf8ff 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -603,7 +603,7 @@ endfunction " ------------------------------------------------------------------ function! s:get_git_root() - let root = split(system('git rev-parse --show-toplevel'), '\n')[0] + let root = split(system('git -C ' . shellescape(expand("%:h")) . ' rev-parse --show-toplevel'), '\n')[0] return v:shell_error ? '' : root endfunction @@ -1181,11 +1181,12 @@ function! s:commits(buffer_local, args) return s:warn('Not in git repository') endif - let source = 'git log '.get(g:, 'fzf_commits_log_options', '--color=always '.fzf#shellescape('--format=%C(auto)%h%d %s %C(green)%cr')) - let current = expand('%') + let current = expand("%:t") + let file_path = expand("%:h") + let source = 'git -C ' .file_path. ' log '.get(g:, 'fzf_commits_log_options', '--color=always '.fzf#shellescape('--format=%C(auto)%h%d %s %C(green)%cr')) let managed = 0 if !empty(current) - call system('git show '.fzf#shellescape(current).' 2> '.(s:is_win ? 'nul' : '/dev/null')) + call system('git -C '.fzf#shellescape(file_path).' show '.fzf#shellescape(current).' 2> '.(s:is_win ? 'nul' : '/dev/null')) let managed = !v:shell_error endif @@ -1216,7 +1217,7 @@ function! s:commits(buffer_local, args) if !s:is_win && &columns > s:wide call extend(options.options, - \ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs git show --format=format: --color=always | head -1000']) + \ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs git -C '.file_path.' show --format=format: --color=always | head -1000']) endif return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)