mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
Make FugitiveChanged event aware of :Git result
If g:fugitive_result is defined during the User FugitiveChanged event, one can trigger a custom behavior based on the arguments in .args or the output in .file. References https://github.com/tpope/vim-fugitive/pull/1015
This commit is contained in:
@@ -2322,7 +2322,9 @@ function! s:TempState(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Result(...) abort
|
function! fugitive#Result(...) abort
|
||||||
if !a:0 || a:1 =~# '^-\=$'
|
if !a:0 && exists('g:fugitive_event')
|
||||||
|
return get(g:, 'fugitive_result', {})
|
||||||
|
elseif !a:0 || type(a:1) == type('') && a:1 =~# '^-\=$'
|
||||||
return get(g:, '_fugitive_last_job', {})
|
return get(g:, '_fugitive_last_job', {})
|
||||||
elseif type(a:1) == type(0)
|
elseif type(a:1) == type(0)
|
||||||
return s:TempState(bufname(a:1))
|
return s:TempState(bufname(a:1))
|
||||||
@@ -2579,7 +2581,7 @@ function! s:RunWait(state, tmp, job, ...) abort
|
|||||||
catch /.*/
|
catch /.*/
|
||||||
endtry
|
endtry
|
||||||
elseif finished
|
elseif finished
|
||||||
call fugitive#ReloadStatus(a:state.dir, 1)
|
call fugitive#ReloadStatus(a:state, 1)
|
||||||
endif
|
endif
|
||||||
endtry
|
endtry
|
||||||
return ''
|
return ''
|
||||||
@@ -2831,7 +2833,8 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
|
|||||||
if editcmd ==# 'edit'
|
if editcmd ==# 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
endif
|
endif
|
||||||
return state.mods . editcmd . ' ' . s:fnameescape(state.file) . '|call fugitive#ReloadStatus(' . string(dir) . ', 1)' . after
|
return state.mods . editcmd . ' ' . s:fnameescape(state.file) .
|
||||||
|
\ '|call fugitive#ReloadStatus(fugitive#Result(' . string(state.file) . '), 1)' . after
|
||||||
elseif has('win32')
|
elseif has('win32')
|
||||||
return 'echoerr ' . string('fugitive: Vim 8 with job support required to use :Git on Windows')
|
return 'echoerr ' . string('fugitive: Vim 8 with job support required to use :Git on Windows')
|
||||||
elseif has('gui_running')
|
elseif has('gui_running')
|
||||||
@@ -3086,9 +3089,12 @@ function! s:DoAutocmdChanged(dir) abort
|
|||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
let g:fugitive_event = dir
|
let g:fugitive_event = dir
|
||||||
|
if type(a:dir) == type({}) && has_key(a:dir, 'args')
|
||||||
|
let g:fugitive_result = a:dir
|
||||||
|
endif
|
||||||
exe s:DoAutocmd('User FugitiveChanged')
|
exe s:DoAutocmd('User FugitiveChanged')
|
||||||
finally
|
finally
|
||||||
unlet! g:fugitive_event
|
unlet! g:fugitive_event g:fugitive_result
|
||||||
" Force statusline reload with the buffer's Git dir
|
" Force statusline reload with the buffer's Git dir
|
||||||
let &ro = &ro
|
let &ro = &ro
|
||||||
endtry
|
endtry
|
||||||
@@ -5636,15 +5642,16 @@ function! s:BlameSubcommand(line1, count, range, bang, mods, options) abort
|
|||||||
let temp_state.file = temp
|
let temp_state.file = temp
|
||||||
call s:RunSave(temp_state)
|
call s:RunSave(temp_state)
|
||||||
if len(ranges + commits + files) || raw
|
if len(ranges + commits + files) || raw
|
||||||
|
let reload = '|call fugitive#ReloadStatus(fugitive#Result(' . string(temp_state.file) . '), 1)'
|
||||||
let mods = s:Mods(a:mods)
|
let mods = s:Mods(a:mods)
|
||||||
if a:count != 0
|
if a:count != 0
|
||||||
exe 'silent keepalt' mods 'split' s:fnameescape(temp)
|
exe 'silent keepalt' mods 'split' s:fnameescape(temp)
|
||||||
elseif !&modified || a:bang || &bufhidden ==# 'hide' || (empty(&bufhidden) && &hidden)
|
elseif !&modified || a:bang || &bufhidden ==# 'hide' || (empty(&bufhidden) && &hidden)
|
||||||
exe 'silent' mods 'edit' . (a:bang ? '! ' : ' ') . s:fnameescape(temp)
|
exe 'silent' mods 'edit' . (a:bang ? '! ' : ' ') . s:fnameescape(temp)
|
||||||
else
|
else
|
||||||
return mods . 'edit ' . s:fnameescape(temp)
|
return mods . 'edit ' . s:fnameescape(temp) . reload
|
||||||
endif
|
endif
|
||||||
return ''
|
return reload[1 : -1]
|
||||||
endif
|
endif
|
||||||
if a:mods =~# '\<tab\>'
|
if a:mods =~# '\<tab\>'
|
||||||
silent tabedit %
|
silent tabedit %
|
||||||
@@ -5709,6 +5716,7 @@ function! s:BlameSubcommand(line1, count, range, bang, mods, options) abort
|
|||||||
call s:Map('n', 'D', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze\\d\\ze\\s\\+\\d\\+)')+1-v:count)<CR>", '<silent>')
|
call s:Map('n', 'D', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze\\d\\ze\\s\\+\\d\\+)')+1-v:count)<CR>", '<silent>')
|
||||||
redraw
|
redraw
|
||||||
syncbind
|
syncbind
|
||||||
|
exe s:DoAutocmdChanged(temp_state)
|
||||||
endif
|
endif
|
||||||
endtry
|
endtry
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ function! FugitiveGitDir(...) abort
|
|||||||
return getbufvar(a:1, 'git_dir')
|
return getbufvar(a:1, 'git_dir')
|
||||||
elseif type(a:1) == type('')
|
elseif type(a:1) == type('')
|
||||||
return substitute(s:Slash(a:1), '/$', '', '')
|
return substitute(s:Slash(a:1), '/$', '', '')
|
||||||
|
elseif type(a:1) == type({})
|
||||||
|
return get(a:1, 'git_dir', '')
|
||||||
else
|
else
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user