diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 35dca8f..6186ecd 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -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')