Account for invalid b:git_dir in FugitiveGitDir()

The "fugitive:" variant was set by a naive regexp in ftplugin/git*.vim
until a relatively recent fix.
This commit is contained in:
Tim Pope
2021-04-12 15:00:36 -04:00
parent ae45609cfc
commit d4e8c29084

View File

@@ -8,6 +8,8 @@ if exists('g:loaded_fugitive')
endif
let g:loaded_fugitive = 1
let s:bad_git_dir = '/$\|^fugitive:'
function! FugitiveGitDir(...) abort
if !a:0 || type(a:1) == type(0) && a:1 < 0
if exists('g:fugitive_event')
@@ -16,16 +18,17 @@ 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)
elseif (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && empty(&buftype)
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
return b:git_dir
endif
return dir
return dir =~# s:bad_git_dir ? '' : dir
elseif type(a:1) == type(0)
if a:1 == bufnr('') && !exists('b:git_dir') && empty(&buftype)
if a:1 == bufnr('') && (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && empty(&buftype)
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
endif
return getbufvar(a:1, 'git_dir')
let dir = getbufvar(a:1, 'git_dir')
return dir =~# s:bad_git_dir ? '' : dir
elseif type(a:1) == type('')
return substitute(s:Slash(a:1), '/$', '', '')
elseif type(a:1) == type({})
@@ -279,7 +282,7 @@ function! FugitiveExtractGitDir(path) abort
endfunction
function! FugitiveDetect(path) abort
if exists('b:git_dir') && b:git_dir =~# '^$\|/$\|^fugitive:'
if exists('b:git_dir') && b:git_dir =~# '^$\|' . s:bad_git_dir
unlet b:git_dir
endif
if !exists('b:git_dir')