Try to avoid interference by $GIT_DIR and $GIT_WORK_TREE

Resolves: https://github.com/tpope/vim-fugitive/issues/1841
This commit is contained in:
Tim Pope
2021-09-17 06:15:08 -04:00
parent 27abc3f1bd
commit a67e1f8189

View File

@@ -428,7 +428,7 @@ function! s:UserCommandList(...) abort
if empty(tree)
call add(git, '--git-dir=' . FugitiveGitPath(dir))
else
if !s:cpath(tree . '/.git', dir)
if !s:cpath(tree . '/.git', dir) || len($GIT_DIR)
call add(git, '--git-dir=' . FugitiveGitPath(dir))
endif
if !s:cpath(tree, getcwd())
@@ -555,6 +555,9 @@ function! s:PrepareEnv(env, dir) abort
let a:env['GIT_INDEX_FILE'] = FugitiveGitPath(fugitive#Find('.git/index', a:dir))
endif
endif
if len($GIT_WORK_TREE)
let a:env['GIT_WORK_TREE'] = '.'
endif
endfunction
let s:prepare_env = {
@@ -712,7 +715,7 @@ function! fugitive#PrepareJob(...) abort
else
let dict.cwd = FugitiveVimPath(tree)
call extend(cmd, ['-C', FugitiveGitPath(tree)], 'keep')
if !s:cpath(tree . '/.git', dir)
if !s:cpath(tree . '/.git', dir) || len($GIT_DIR)
call extend(cmd, ['--git-dir=' . FugitiveGitPath(dir)], 'keep')
endif
endif
@@ -750,7 +753,7 @@ function! s:BuildShell(dir, env, git, args) abort
call insert(cmd, '--git-dir=' . FugitiveGitPath(a:dir))
else
call extend(cmd, ['-C', FugitiveGitPath(tree)], 'keep')
if !s:cpath(tree . '/.git', a:dir)
if !s:cpath(tree . '/.git', a:dir) || len($GIT_DIR)
call extend(cmd, ['--git-dir=' . FugitiveGitPath(a:dir)], 'keep')
endif
endif