diff --git a/plug.vim b/plug.vim index 80f9629..60e6bf5 100644 --- a/plug.vim +++ b/plug.vim @@ -656,6 +656,7 @@ function! s:do(pull, force, todo) if a:force || installed || updated execute 'cd' s:esc(spec.dir) call append(3, '- Post-update hook for '. name .' ... ') + let error = '' let type = type(spec.do) if type == s:TYPE.string try @@ -664,21 +665,23 @@ function! s:do(pull, force, todo) let g:_plug_do = '!'.escape(spec.do, '#!%') execute "normal! :execute g:_plug_do\\" finally - let result = v:shell_error ? ('Exit status: '.v:shell_error) : 'Done!' + if v:shell_error + let error = 'Exit status: ' . v:shell_error + endif unlet g:_plug_do endtry elseif type == s:TYPE.funcref try let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') call spec.do({ 'name': name, 'status': status, 'force': a:force }) - let result = 'Done!' catch - let result = 'Error: ' . v:exception + let error = v:exception endtry else - let result = 'Error: Invalid type!' + let error = 'Invalid hook type' endif - call setline(4, getline(4) . result) + call setline(4, empty(error) ? (getline(4) . 'OK') + \ : ('x' . getline(4)[1:] . error)) cd - endif endfor diff --git a/test/workflow.vader b/test/workflow.vader index fa47238..6785293 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -756,6 +756,28 @@ Execute (Using Funcref): Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclunchanged13'), \ 'vim-pseudocl/vim-pseudoclunchanged13 should exist' +Execute (Post-update hook output; success and failure): + call plug#begin() + Plug 'junegunn/vim-easy-align', { 'do': 'xxx-non-existent-command-xxx' } + Plug 'junegunn/vim-pseudocl', { 'do': 'true' } + call plug#end() + + silent PlugInstall! 1 + AssertEqual '- Post-update hook for vim-pseudocl ... OK', getline(5) + AssertEqual 'x Post-update hook for vim-easy-align ... Exit status: 127', getline(6) + q + +Execute (Post-update hook output; invalid type or funcref): + call plug#begin() + Plug 'junegunn/vim-easy-align', { 'do': 1 } + Plug 'junegunn/vim-pseudocl', { 'do': function('call') } + call plug#end() + + silent PlugInstall! 1 + AssertEqual 'x Post-update hook for vim-pseudocl ... Vim(call):E119: Not enough arguments for function: call', getline(5) + AssertEqual 'x Post-update hook for vim-easy-align ... Invalid hook type', getline(6) + q + Execute (Should not run when failed to update): call plug#begin() Plug 'junegunn/vim-easy-align', { 'do': 'touch failed' }