Trigger User FugitiveChanged on events that change repository

Note that in the context of this event, Fugitive functions will use the
changed repository, which might not be the same as the current buffer's
repository.  Pass bufnr() as the optional dir argument to force the
current buffer.

Closes https://github.com/tpope/vim-fugitive/issues/458
This commit is contained in:
Tim Pope
2019-09-27 09:22:05 -04:00
parent fee14c149c
commit ab26e9fdb3
2 changed files with 33 additions and 10 deletions

View File

@@ -2323,8 +2323,23 @@ function! s:StageSeek(info, fallback) abort
return exists('backup') ? backup : line - 1
endfunction
function! s:ReloadStatus(...) abort
call s:ExpireStatus(-1)
function! s:DoAutocmdChanged(dir) abort
let dir = a:dir is# -2 ? '' : FugitiveGitDir(a:dir)
if empty(dir) || !exists('#User#FugitiveChanged') || exists('g:fugitive_event')
return ''
endif
try
let g:fugitive_event = dir
exe s:DoAutocmd('User FugitiveChanged')
finally
unlet! g:fugitive_event
" Force statusline reload with the buffer's Git dir
let &ro = &ro
endtry
return ''
endfunction
function! s:ReloadStatusBuffer(...) abort
if get(b:, 'fugitive_type', '') !=# 'index'
return ''
endif
@@ -2336,6 +2351,13 @@ function! s:ReloadStatus(...) abort
return ''
endfunction
function! s:ReloadStatus(...) abort
call s:ExpireStatus(-1)
call s:ReloadStatusBuffer(a:0 ? a:1 : line('.'))
exe s:DoAutocmdChanged(-1)
return ''
endfunction
let s:last_time = reltime()
if !exists('s:last_times')
let s:last_times = {}
@@ -2364,13 +2386,13 @@ function! s:ReloadWinStatus(...) abort
return
endif
if !exists('b:fugitive_reltime')
exe s:ReloadStatus()
exe s:ReloadStatusBuffer()
return
endif
let t = b:fugitive_reltime
if reltimestr(reltime(s:last_time, t)) =~# '-\|\d\{10\}\.' ||
\ reltimestr(reltime(get(s:last_times, s:cpath(s:Dir()), t), t)) =~# '-\|\d\{10\}\.'
exe s:ReloadStatus()
exe s:ReloadStatusBuffer()
endif
endfunction
@@ -2399,21 +2421,19 @@ function! s:ReloadTabStatus(...) abort
endfunction
function! fugitive#ReloadStatus(...) abort
call s:ExpireStatus(a:0 ? a:1 : -2)
if a:0 > 1 ? a:2 : s:CanAutoReloadStatus()
call s:ExpireStatus(a:0 ? a:1 : -1)
if a:0 > 1 ? a:2 : 1
let t = reltime()
let t:fugitive_reload_status = t
for tabnr in exists('*settabvar') ? range(1, tabpagenr('$')) : []
call settabvar(tabnr, 'fugitive_reload_status', t)
endfor
call s:ReloadTabStatus()
exe s:DoAutocmdChanged(a:0 ? a:1 : -1)
else
call s:ReloadWinStatus()
endif
endfunction
function! s:CanAutoReloadStatus() abort
return get(g:, 'fugitive_autoreload_status', !has('win32'))
return ''
endfunction
function! fugitive#EfmDir(...) abort

View File

@@ -10,6 +10,9 @@ let g:loaded_fugitive = 1
function! FugitiveGitDir(...) abort
if !a:0 || type(a:1) == type(0) && a:1 < 0
if exists('g:fugitive_event')
return g:fugitive_event
endif
let dir = get(b:, 'git_dir', '')
if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|prompt\)$')
return FugitiveExtractGitDir(getcwd())