From 93f29cf831261ddc15d2a7d09a662c0749e8f2fb Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 23 Jul 2018 13:49:32 -0400 Subject: [PATCH] Fix shelling out from subdirectory Closes https://github.com/tpope/vim-fugitive/issues/1061 --- autoload/fugitive.vim | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index abb3721..7ec6047 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -117,12 +117,24 @@ function! fugitive#Prepare(...) abort endfunction function! s:TreeChomp(...) abort - let args = ['--git-dir=' . b:git_dir] + a:000 + let args = a:000 let tree = FugitiveTreeForGitDir(b:git_dir) - if !empty(tree) - call insert(args, '--work-tree=' . tree) - endif - return s:sub(s:System(call('fugitive#Prepare', args)),'\n$','') + try + if !empty(tree) + if fugitive#GitVersion() =~# '^[01]\..*' + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' + let cwd = getcwd() + exe cd s:fnameescape(tree) + else + let args = ['-C', tree] + args + endif + endif + return s:sub(s:System(call('fugitive#Prepare', args)),'\n$','') + finally + if exists('l:cd') + exe cd s:fnameescape(cwd) + endif + endtry endfunction let s:git_versions = {}