Fix shelling out from subdirectory

Closes https://github.com/tpope/vim-fugitive/issues/1061
This commit is contained in:
Tim Pope 2018-07-23 13:49:32 -04:00
parent 5879304769
commit 93f29cf831

View File

@ -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 = {}