Proactively detect Git dir if autocommand hasn't triggered

This is a little clunky, but enabling !empty(FugitiveGitDir()) to work
in autocommands that trigger before ours should provide an acceptable
replacement for the "User Fugitive" event and will hopefully enable us
to unltimately eliminate preemptive detection entirely.
This commit is contained in:
Tim Pope
2021-04-12 14:29:53 -04:00
parent 54cc9d01ad
commit ae45609cfc

View File

@@ -16,9 +16,15 @@ function! FugitiveGitDir(...) abort
let dir = get(b:, 'git_dir', '') let dir = get(b:, 'git_dir', '')
if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|prompt\)$') if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|prompt\)$')
return FugitiveExtractGitDir(getcwd()) return FugitiveExtractGitDir(getcwd())
elseif !exists('b:git_dir') && empty(&buftype)
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
return b:git_dir
endif endif
return dir return dir
elseif type(a:1) == type(0) elseif type(a:1) == type(0)
if a:1 == bufnr('') && !exists('b:git_dir') && empty(&buftype)
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
endif
return getbufvar(a:1, 'git_dir') return getbufvar(a:1, 'git_dir')
elseif type(a:1) == type('') elseif type(a:1) == type('')
return substitute(s:Slash(a:1), '/$', '', '') return substitute(s:Slash(a:1), '/$', '', '')