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 return exists('backup') ? backup : line - 1
endfunction endfunction
function! s:ReloadStatus(...) abort function! s:DoAutocmdChanged(dir) abort
call s:ExpireStatus(-1) 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' if get(b:, 'fugitive_type', '') !=# 'index'
return '' return ''
endif endif
@@ -2336,6 +2351,13 @@ function! s:ReloadStatus(...) abort
return '' return ''
endfunction 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() let s:last_time = reltime()
if !exists('s:last_times') if !exists('s:last_times')
let s:last_times = {} let s:last_times = {}
@@ -2364,13 +2386,13 @@ function! s:ReloadWinStatus(...) abort
return return
endif endif
if !exists('b:fugitive_reltime') if !exists('b:fugitive_reltime')
exe s:ReloadStatus() exe s:ReloadStatusBuffer()
return return
endif endif
let t = b:fugitive_reltime let t = b:fugitive_reltime
if reltimestr(reltime(s:last_time, t)) =~# '-\|\d\{10\}\.' || if reltimestr(reltime(s:last_time, t)) =~# '-\|\d\{10\}\.' ||
\ reltimestr(reltime(get(s:last_times, s:cpath(s:Dir()), t), t)) =~# '-\|\d\{10\}\.' \ reltimestr(reltime(get(s:last_times, s:cpath(s:Dir()), t), t)) =~# '-\|\d\{10\}\.'
exe s:ReloadStatus() exe s:ReloadStatusBuffer()
endif endif
endfunction endfunction
@@ -2399,21 +2421,19 @@ function! s:ReloadTabStatus(...) abort
endfunction endfunction
function! fugitive#ReloadStatus(...) abort function! fugitive#ReloadStatus(...) abort
call s:ExpireStatus(a:0 ? a:1 : -2) call s:ExpireStatus(a:0 ? a:1 : -1)
if a:0 > 1 ? a:2 : s:CanAutoReloadStatus() if a:0 > 1 ? a:2 : 1
let t = reltime() let t = reltime()
let t:fugitive_reload_status = t let t:fugitive_reload_status = t
for tabnr in exists('*settabvar') ? range(1, tabpagenr('$')) : [] for tabnr in exists('*settabvar') ? range(1, tabpagenr('$')) : []
call settabvar(tabnr, 'fugitive_reload_status', t) call settabvar(tabnr, 'fugitive_reload_status', t)
endfor endfor
call s:ReloadTabStatus() call s:ReloadTabStatus()
exe s:DoAutocmdChanged(a:0 ? a:1 : -1)
else else
call s:ReloadWinStatus() call s:ReloadWinStatus()
endif endif
endfunction return ''
function! s:CanAutoReloadStatus() abort
return get(g:, 'fugitive_autoreload_status', !has('win32'))
endfunction endfunction
function! fugitive#EfmDir(...) abort function! fugitive#EfmDir(...) abort

View File

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