Remove Git dir checks on FileType events

In order for these checks to work, :filetype on must be invoked *after*
Fugitive is loaded.  Otherwise, the FileType event triggers before
FugitiveDetect() is called.

These file types are used almost exclusively inside of Git repositories,
and in the rare case they are not, we're not doing anything particularly
intrusive, so dropping the conditional should have little practical
impact.  An exception is fugitive#MapJumps(), which is designed to be
used exclusively with historical buffers, the status buffer, and
captured :Git output, so let's lock it down to those particular
workflows.
This commit is contained in:
Tim Pope
2021-03-13 23:27:28 -05:00
parent f2956a923d
commit 10121f34f2
2 changed files with 20 additions and 15 deletions

View File

@@ -2273,7 +2273,10 @@ function! s:TempReadPost(file) abort
if has_key(s:temp_files, s:cpath(a:file)) if has_key(s:temp_files, s:cpath(a:file))
let dict = s:temp_files[s:cpath(a:file)] let dict = s:temp_files[s:cpath(a:file)]
setlocal nobuflisted setlocal nobuflisted
if has_key(dict, 'filetype') && dict.filetype !=# &l:filetype if get(dict, 'filetype', '') ==# 'git'
call fugitive#MapJumps()
endif
if has_key(dict, 'filetype')
let &l:filetype = dict.filetype let &l:filetype = dict.filetype
endif endif
setlocal foldmarker=<<<<<<<,>>>>>>> setlocal foldmarker=<<<<<<<,>>>>>>>
@@ -6117,6 +6120,9 @@ endfunction
function! s:StatusCfile(...) abort function! s:StatusCfile(...) abort
let tree = s:Tree() let tree = s:Tree()
if empty(tree)
return ['']
endif
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/' let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
let info = s:StageInfo() let info = s:StageInfo()
let line = getline('.') let line = getline('.')
@@ -6146,6 +6152,9 @@ endfunction
function! s:MessageCfile(...) abort function! s:MessageCfile(...) abort
let tree = s:Tree() let tree = s:Tree()
if empty(tree)
return ''
endif
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/' let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
if getline('.') =~# '^.\=\trenamed:.* -> ' if getline('.') =~# '^.\=\trenamed:.* -> '
return lead . matchstr(getline('.'),' -> \zs.*') return lead . matchstr(getline('.'),' -> \zs.*')
@@ -6172,6 +6181,9 @@ function! fugitive#MessageCfile() abort
endfunction endfunction
function! s:cfile() abort function! s:cfile() abort
if empty(FugitiveGitDir())
return []
endif
try try
let myhash = s:DirRev(@%)[1] let myhash = s:DirRev(@%)[1]
if len(myhash) if len(myhash)

View File

@@ -363,27 +363,20 @@ augroup fugitive
autocmd FileType netrw call FugitiveDetect(fnamemodify(get(b:, 'netrw_curdir', expand('<amatch>')), ':p')) autocmd FileType netrw call FugitiveDetect(fnamemodify(get(b:, 'netrw_curdir', expand('<amatch>')), ':p'))
autocmd FileType git autocmd FileType git
\ if len(FugitiveGitDir()) | \ call fugitive#MapCfile()
\ call fugitive#MapJumps() |
\ call fugitive#MapCfile() |
\ endif
autocmd FileType gitcommit autocmd FileType gitcommit
\ if len(FugitiveGitDir()) | \ call fugitive#MapCfile('fugitive#MessageCfile()')
\ call fugitive#MapCfile('fugitive#MessageCfile()') |
\ endif
autocmd FileType git,gitcommit autocmd FileType git,gitcommit
\ if len(FugitiveGitDir()) && &foldtext ==# 'foldtext()' | \ if &foldtext ==# 'foldtext()' |
\ setlocal foldtext=fugitive#Foldtext() | \ setlocal foldtext=fugitive#Foldtext() |
\ endif \ endif
autocmd FileType fugitive autocmd FileType fugitive
\ if len(FugitiveGitDir()) | \ call fugitive#MapCfile('fugitive#StatusCfile()')
\ call fugitive#MapCfile('fugitive#StatusCfile()') |
\ endif
autocmd FileType gitrebase autocmd FileType gitrebase
\ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' | \ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' |
\ if len(FugitiveGitDir()) | \ if &l:includeexpr !~# 'Fugitive' |
\ let &l:includeexpr = 'v:fname =~# ''^\x\{4,\}$'' ? FugitiveFind(v:fname) : ' . \ let &l:includeexpr = 'v:fname =~# ''^\x\{4,\}$'' && len(FugitiveGitDir()) ? FugitiveFind(v:fname) : ' .
\ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') | \ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') |
\ endif | \ endif |
\ let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setl inex= inc=' \ let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setl inex= inc='