Look for "fugitive_dir" as dictionary key

Work trees and submodules have two things that could be called the Git
dir: the directory itself, and the ".git" at the root of the work tree.
Introduce "fugitive_dir" as our name for the one we consider canonical.
This commit is contained in:
Tim Pope
2022-06-20 20:16:08 -04:00
parent 8b39d29d94
commit aafbdf84cd
2 changed files with 14 additions and 13 deletions

View File

@@ -628,9 +628,9 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
throw 'fugitive: Git 1.8.5 or higher required' throw 'fugitive: Git 1.8.5 or higher required'
endif endif
let git = s:GitCmd() let git = s:GitCmd()
if a:0 == 1 && type(a:1) == type({}) && has_key(a:1, 'git_dir') && has_key(a:1, 'flags') && has_key(a:1, 'args') if a:0 == 1 && type(a:1) == type({}) && (has_key(a:1, 'fugitive_dir') || has_key(a:1, 'git_dir')) && has_key(a:1, 'flags') && has_key(a:1, 'args')
let cmd = a:1.flags + a:1.args let cmd = a:1.flags + a:1.args
let dir = a:1.git_dir let dir = s:Dir(a:1)
if has_key(a:1, 'git') if has_key(a:1, 'git')
let git = a:1.git let git = a:1.git
endif endif
@@ -655,8 +655,8 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
let arg_count = 0 let arg_count = 0
while i < len(cmd) while i < len(cmd)
if type(cmd[i]) == type({}) if type(cmd[i]) == type({})
if has_key(cmd[i], 'git_dir') if has_key(cmd[i], 'fugitive_dir') || has_key(cmd[i], 'git_dir')
let dir = cmd[i].git_dir let dir = s:Dir(cmd[i])
endif endif
if has_key(cmd[i], 'git') if has_key(cmd[i], 'git')
let git = cmd[i].git let git = cmd[i].git
@@ -666,9 +666,9 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
endif endif
call remove(cmd, i) call remove(cmd, i)
elseif cmd[i] =~# '^$\|[\/.]' && cmd[i] !~# '^-' elseif cmd[i] =~# '^$\|[\/.]' && cmd[i] !~# '^-'
let dir = remove(cmd, i) let dir = s:Dir(remove(cmd, i))
elseif cmd[i] =~# '^--git-dir=' elseif cmd[i] =~# '^--git-dir='
let dir = remove(cmd, i)[10:-1] let dir = s:Dir(remove(cmd, i)[10:-1])
elseif type(cmd[i]) ==# type(0) elseif type(cmd[i]) ==# type(0)
let dir = s:Dir(remove(cmd, i)) let dir = s:Dir(remove(cmd, i))
elseif cmd[i] ==# '-c' && len(cmd) > i + 1 elseif cmd[i] ==# '-c' && len(cmd) > i + 1
@@ -699,7 +699,7 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
let autoenv.GPG_TTY = '' let autoenv.GPG_TTY = ''
endif endif
call s:PreparePathArgs(cmd, dir, literal_pathspecs, explicit_pathspec_option) call s:PreparePathArgs(cmd, dir, literal_pathspecs, explicit_pathspec_option)
return [s:GitDir(dir), env, extend(autoenv, env), git, cmd[0 : -arg_count-1], arg_count ? cmd[-arg_count : -1] : []] return [dir, env, extend(autoenv, env), git, cmd[0 : -arg_count-1], arg_count ? cmd[-arg_count : -1] : []]
endfunction endfunction
function! s:BuildEnvPrefix(env) abort function! s:BuildEnvPrefix(env) abort
@@ -758,13 +758,14 @@ function! fugitive#PrepareJob(...) abort
if a:0 == 1 && type(a:1) == type({}) && has_key(a:1, 'argv') && !has_key(a:1, 'args') if a:0 == 1 && type(a:1) == type({}) && has_key(a:1, 'argv') && !has_key(a:1, 'args')
return s:PrepareJob(a:1) return s:PrepareJob(a:1)
endif endif
let [dir, user_env, exec_env, git, flags, args] = call('fugitive#PrepareDirEnvGitFlagsArgs', a:000) let [repo, user_env, exec_env, git, flags, args] = call('fugitive#PrepareDirEnvGitFlagsArgs', a:000)
let dir = s:GitDir(repo)
let dict = {'git': git, 'git_dir': dir, 'flags': flags, 'args': args} let dict = {'git': git, 'git_dir': dir, 'flags': flags, 'args': args}
if len(user_env) if len(user_env)
let dict.env = user_env let dict.env = user_env
endif endif
let cmd = flags + args let cmd = flags + args
let tree = s:Tree(dir) let tree = s:Tree(repo)
if empty(tree) || index(cmd, '--') == len(cmd) - 1 if empty(tree) || index(cmd, '--') == len(cmd) - 1
let dict.cwd = getcwd() let dict.cwd = getcwd()
call extend(cmd, ['--git-dir=' . FugitiveGitPath(dir)], 'keep') call extend(cmd, ['--git-dir=' . FugitiveGitPath(dir)], 'keep')
@@ -860,8 +861,8 @@ function! s:SystemList(cmd) abort
endfunction endfunction
function! fugitive#ShellCommand(...) abort function! fugitive#ShellCommand(...) abort
let [dir, _, env, git, flags, args] = call('fugitive#PrepareDirEnvGitFlagsArgs', a:000) let [repo, _, env, git, flags, args] = call('fugitive#PrepareDirEnvGitFlagsArgs', a:000)
return s:BuildShell(dir, env, git, flags + args) return s:BuildShell(s:GitDir(repo), env, git, flags + args)
endfunction endfunction
function! s:SystemError(cmd, ...) abort function! s:SystemError(cmd, ...) abort

View File

@@ -39,7 +39,7 @@ function! FugitiveGitDir(...) abort
elseif type(a:1) == type('') elseif type(a:1) == type('')
return substitute(s:Slash(a:1), '/$', '', '') return substitute(s:Slash(a:1), '/$', '', '')
elseif type(a:1) == type({}) elseif type(a:1) == type({})
return get(a:1, 'git_dir', '') return get(a:1, 'fugitive_dir', get(a:1, 'git_dir', ''))
else else
return '' return ''
endif endif
@@ -423,7 +423,7 @@ endfunction
function! FugitiveExtractGitDir(path) abort function! FugitiveExtractGitDir(path) abort
if type(a:path) ==# type({}) if type(a:path) ==# type({})
return get(a:path, 'git_dir', '') return get(a:1, 'fugitive_dir', get(a:1, 'git_dir', ''))
elseif type(a:path) == type(0) elseif type(a:path) == type(0)
let path = s:Slash(a:path > 0 ? bufname(a:path) : bufname('')) let path = s:Slash(a:path > 0 ? bufname(a:path) : bufname(''))
else else