commit 93f29cf831261ddc15d2a7d09a662c0749e8f2fb (tree)
parent 587930476918f136122da44bb13bb0deb4764844
Author: Tim Pope <code@tpope.net>
Date: Mon, 23 Jul 2018 13:49:32 -0400
Fix shelling out from subdirectory
Closes https://github.com/tpope/vim-fugitive/issues/1061
Diffstat:
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git 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 = {}