From a67e1f8189938c44f295fc97e6c9dd13b727b1e3 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 17 Sep 2021 06:15:08 -0400 Subject: [PATCH] Try to avoid interference by $GIT_DIR and $GIT_WORK_TREE Resolves: https://github.com/tpope/vim-fugitive/issues/1841 --- autoload/fugitive.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index a1eb262..5173b49 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -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