mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-14 22:33:51 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user