commit ab26e9fdb328cc351933f8d6178178e8ce5c8381 (tree)
parent fee14c149cbdbdae3e7272705dea73603bb89105
Author: Tim Pope <code@tpope.net>
Date: Fri, 27 Sep 2019 09:22:05 -0400
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
Diffstat:
2 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -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
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -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())