Try embedding shell cd if -C not available

Old Git versions lacking -C are often paired with old Vim versions
lacking haslocaldir(), so chance some shell weirdness over screwing up
Vim's local directory.
This commit is contained in:
Tim Pope
2018-07-26 15:11:47 -04:00
parent 6bab1a0c39
commit c3c39d904b

View File

@@ -116,31 +116,6 @@ function! fugitive#Prepare(...) abort
return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'), ' ')
endfunction
function! s:TreeChomp(...) abort
let args = a:000
let tree = FugitiveTreeForGitDir(b:git_dir)
try
if !empty(tree)
if fugitive#GitVersion() =~# '^[01]\..*'
if getcwd() !=# tree
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
let cwd = getcwd()
exe cd s:fnameescape(tree)
endif
else
let args = ['-C', tree] + args
endif
else
let args = ['--git-dir=' . b:git_dir] . args
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 = {}
function! fugitive#GitVersion(...) abort
if !has_key(s:git_versions, g:fugitive_git_executable)
@@ -149,6 +124,22 @@ function! fugitive#GitVersion(...) abort
return s:git_versions[g:fugitive_git_executable]
endfunction
function! s:TreeChomp(...) abort
let args = copy(a:000)
let tree = FugitiveTreeForGitDir(b:git_dir)
let pre = ''
if empty(tree)
let args = ['--git-dir=' . b:git_dir] . args
elseif s:cpath(tree) !=# s:cpath(getcwd())
if fugitive#GitVersion() =~# '^[01]\.'
let pre = 'cd ' . s:shellesc(tree) . (s:winshell() ? ' & ' : '; ')
else
let args = ['-C', tree] + args
endif
endif
return s:sub(s:System(pre . call('fugitive#Prepare', args)),'\n$','')
endfunction
function! fugitive#Config(name, ...) abort
let cmd = fugitive#Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name)
let out = matchstr(system(cmd), "[^\r\n]*")