mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-15 06:43:51 -05:00
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:
@@ -116,31 +116,6 @@ function! fugitive#Prepare(...) abort
|
|||||||
return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'), ' ')
|
return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'), ' ')
|
||||||
endfunction
|
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 = {}
|
let s:git_versions = {}
|
||||||
function! fugitive#GitVersion(...) abort
|
function! fugitive#GitVersion(...) abort
|
||||||
if !has_key(s:git_versions, g:fugitive_git_executable)
|
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]
|
return s:git_versions[g:fugitive_git_executable]
|
||||||
endfunction
|
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
|
function! fugitive#Config(name, ...) abort
|
||||||
let cmd = fugitive#Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name)
|
let cmd = fugitive#Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name)
|
||||||
let out = matchstr(system(cmd), "[^\r\n]*")
|
let out = matchstr(system(cmd), "[^\r\n]*")
|
||||||
|
|||||||
Reference in New Issue
Block a user