commit ae45609cfc3fae91bb7859dde95cb0aee493f34c (tree)
parent 54cc9d01ad3f0a0a9d9b9fd4bd58ae699e38e5fa
Author: Tim Pope <code@tpope.net>
Date: Mon, 12 Apr 2021 14:29:53 -0400
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.
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -16,9 +16,15 @@ function! FugitiveGitDir(...) abort
let dir = get(b:, 'git_dir', '')
if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|prompt\)$')
return FugitiveExtractGitDir(getcwd())
+ elseif !exists('b:git_dir') && empty(&buftype)
+ let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
+ return b:git_dir
endif
return dir
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')
elseif type(a:1) == type('')
return substitute(s:Slash(a:1), '/$', '', '')