From ae45609cfc3fae91bb7859dde95cb0aee493f34c Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 12 Apr 2021 14:29:53 -0400 Subject: [PATCH] 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. --- plugin/fugitive.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 0c3affe..35dca8f 100644 --- 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), '/$', '', '')