mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-19 10:35:38 -07:00
Forced run of post-update hooks using bang commands
PlugInstall! / PlugUpdate!
This commit is contained in:
parent
01e126469b
commit
93628b1c3d
14
README.md
14
README.md
@ -134,10 +134,11 @@ takes a single argument.
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
function! BuildYCM(info)
|
function! BuildYCM(info)
|
||||||
" info is a dictionary with two fields
|
" info is a dictionary with 3 fields
|
||||||
" - name: name of the plugin
|
" - name: name of the plugin
|
||||||
" - status: 'installed' or 'updated'
|
" - status: 'installed', 'updated', or 'unchanged'
|
||||||
if a:info.status == 'installed'
|
" - force: set on PlugInstall! or PlugUpdate!
|
||||||
|
if a:info.status == 'installed' || a:info.force
|
||||||
!./install.sh
|
!./install.sh
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@ -145,7 +146,10 @@ endfunction
|
|||||||
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
|
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
|
||||||
```
|
```
|
||||||
|
|
||||||
Both forms of post-update hook are executed inside the directory of the plugin.
|
Both forms of post-update hook are executed inside the directory of the plugin
|
||||||
|
and only run when the repository has changed, but you can force it to run
|
||||||
|
unconditionally with the bang-versions of the commands: `PlugInstall!` and
|
||||||
|
`PlugUpdate!`.
|
||||||
|
|
||||||
Make sure to escape BARs when you write `do` option inline as they are
|
Make sure to escape BARs when you write `do` option inline as they are
|
||||||
mistakenly recognized as command separator for Plug command.
|
mistakenly recognized as command separator for Plug command.
|
||||||
|
30
plug.vim
30
plug.vim
@ -109,8 +109,8 @@ function! plug#begin(...)
|
|||||||
let g:plugs_order = []
|
let g:plugs_order = []
|
||||||
|
|
||||||
command! -nargs=+ -bar Plug call s:add(<args>)
|
command! -nargs=+ -bar Plug call s:add(<args>)
|
||||||
command! -nargs=* -complete=customlist,s:names PlugInstall call s:install(<f-args>)
|
command! -nargs=* -bang -complete=customlist,s:names PlugInstall call s:install(!empty('<bang>'), <f-args>)
|
||||||
command! -nargs=* -complete=customlist,s:names PlugUpdate call s:update(<f-args>)
|
command! -nargs=* -bang -complete=customlist,s:names PlugUpdate call s:update(!empty('<bang>'), <f-args>)
|
||||||
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
||||||
command! -nargs=0 PlugUpgrade if s:upgrade() | call s:upgrade_specs() | execute 'source '. s:me | endif
|
command! -nargs=0 PlugUpgrade if s:upgrade() | call s:upgrade_specs() | execute 'source '. s:me | endif
|
||||||
command! -nargs=0 PlugStatus call s:status()
|
command! -nargs=0 PlugStatus call s:status()
|
||||||
@ -365,12 +365,12 @@ function! s:infer_properties(name, repo)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:install(...)
|
function! s:install(force, ...)
|
||||||
call s:update_impl(0, a:000)
|
call s:update_impl(0, a:force, a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update(...)
|
function! s:update(force, ...)
|
||||||
call s:update_impl(1, a:000)
|
call s:update_impl(1, a:force, a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:helptags()
|
function! s:helptags()
|
||||||
@ -470,15 +470,16 @@ function! s:assign_name()
|
|||||||
silent! execute 'f '.fnameescape(name)
|
silent! execute 'f '.fnameescape(name)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:do(pull, todo)
|
function! s:do(pull, force, todo)
|
||||||
for [name, spec] in items(a:todo)
|
for [name, spec] in items(a:todo)
|
||||||
if !isdirectory(spec.dir)
|
if !isdirectory(spec.dir)
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
execute 'cd '.s:esc(spec.dir)
|
execute 'cd '.s:esc(spec.dir)
|
||||||
let installed = has_key(s:prev_update.new, name)
|
let installed = has_key(s:prev_update.new, name)
|
||||||
if installed || (a:pull &&
|
let updated = installed ? 0 :
|
||||||
\ !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"')))
|
\ (a:pull && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"')))
|
||||||
|
if a:force || installed || updated
|
||||||
call append(3, '- Post-update hook for '. name .' ... ')
|
call append(3, '- Post-update hook for '. name .' ... ')
|
||||||
let type = type(spec.do)
|
let type = type(spec.do)
|
||||||
if type == s:TYPE.string
|
if type == s:TYPE.string
|
||||||
@ -493,7 +494,8 @@ function! s:do(pull, todo)
|
|||||||
endtry
|
endtry
|
||||||
elseif type == s:TYPE.funcref
|
elseif type == s:TYPE.funcref
|
||||||
try
|
try
|
||||||
call spec.do({ 'name': name, 'status': (installed ? 'installed' : 'updated') })
|
let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged')
|
||||||
|
call spec.do({ 'name': name, 'status': status, 'force': a:force })
|
||||||
let result = 'Done!'
|
let result = 'Done!'
|
||||||
catch
|
catch
|
||||||
let result = 'Error: ' . v:exception
|
let result = 'Error: ' . v:exception
|
||||||
@ -530,7 +532,7 @@ function! s:retry()
|
|||||||
if empty(s:prev_update.errors)
|
if empty(s:prev_update.errors)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
call s:update_impl(s:prev_update.pull,
|
call s:update_impl(s:prev_update.pull, s:prev_update.force,
|
||||||
\ extend(copy(s:prev_update.errors), [s:prev_update.threads]))
|
\ extend(copy(s:prev_update.errors), [s:prev_update.threads]))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -542,7 +544,7 @@ function! s:names(...)
|
|||||||
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')
|
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update_impl(pull, args) abort
|
function! s:update_impl(pull, force, args) abort
|
||||||
let st = reltime()
|
let st = reltime()
|
||||||
let args = copy(a:args)
|
let args = copy(a:args)
|
||||||
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||||
@ -568,7 +570,7 @@ function! s:update_impl(pull, args) abort
|
|||||||
if !isdirectory(g:plug_home)
|
if !isdirectory(g:plug_home)
|
||||||
call mkdir(g:plug_home, 'p')
|
call mkdir(g:plug_home, 'p')
|
||||||
endif
|
endif
|
||||||
let s:prev_update = { 'errors': [], 'pull': a:pull, 'new': {}, 'threads': threads }
|
let s:prev_update = { 'errors': [], 'pull': a:pull, 'force': a:force, 'new': {}, 'threads': threads }
|
||||||
if has('ruby') && threads > 1
|
if has('ruby') && threads > 1
|
||||||
try
|
try
|
||||||
let imd = &imd
|
let imd = &imd
|
||||||
@ -598,7 +600,7 @@ function! s:update_impl(pull, args) abort
|
|||||||
else
|
else
|
||||||
call s:update_serial(a:pull, todo)
|
call s:update_serial(a:pull, todo)
|
||||||
endif
|
endif
|
||||||
call s:do(a:pull, filter(copy(todo), 'has_key(v:val, "do")'))
|
call s:do(a:pull, a:force, filter(copy(todo), 'has_key(v:val, "do")'))
|
||||||
call s:finish(a:pull)
|
call s:finish(a:pull)
|
||||||
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(st)))[0] . ' sec.')
|
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(st)))[0] . ' sec.')
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -621,6 +621,14 @@ Execute (When already installed):
|
|||||||
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
|
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
|
||||||
\ 'vim-easy-align/installed2 should not exist'
|
\ 'vim-easy-align/installed2 should not exist'
|
||||||
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
|
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
|
||||||
|
\ 'vim-pseudocl/installed2 should not exist'
|
||||||
|
|
||||||
|
Execute (PlugInstall!):
|
||||||
|
PlugInstall!
|
||||||
|
q
|
||||||
|
Assert filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
|
||||||
|
\ 'vim-easy-align/installed2 should exist'
|
||||||
|
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
|
||||||
\ 'vim-pseudocl/installed2 should exist'
|
\ 'vim-pseudocl/installed2 should exist'
|
||||||
|
|
||||||
Execute (When already updated):
|
Execute (When already updated):
|
||||||
@ -634,11 +642,19 @@ Execute (When already updated):
|
|||||||
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
|
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
|
||||||
\ 'vim-easy-align/updated2 should not exist'
|
\ 'vim-easy-align/updated2 should not exist'
|
||||||
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
|
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
|
||||||
|
\ 'vim-pseudocl/updated2 should not exist'
|
||||||
|
|
||||||
|
Execute (PlugUpdate!):
|
||||||
|
PlugUpdate!
|
||||||
|
q
|
||||||
|
Assert filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
|
||||||
|
\ 'vim-easy-align/updated2 should exist'
|
||||||
|
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
|
||||||
\ 'vim-pseudocl/updated2 should exist'
|
\ 'vim-pseudocl/updated2 should exist'
|
||||||
|
|
||||||
Execute (Using Funcref):
|
Execute (Using Funcref):
|
||||||
function! PlugUpdated(info)
|
function! PlugUpdated(info)
|
||||||
call system('touch '. a:info.name . a:info.status . len(a:info))
|
call system('touch '. a:info.name . a:info.status . a:info.force . len(a:info))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
@ -652,11 +668,26 @@ Execute (Using Funcref):
|
|||||||
PlugUpdate
|
PlugUpdate
|
||||||
Log getline(1, '$')
|
Log getline(1, '$')
|
||||||
q
|
q
|
||||||
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated2'),
|
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated03'),
|
||||||
\ 'vim-easy-align/vim-easy-alignupdated2 should exist'
|
\ 'vim-easy-align/vim-easy-alignupdated03 should exist'
|
||||||
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled2'),
|
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled03'),
|
||||||
\ 'vim-pseudocl/vim-pseudoclinstalled2 should exist'
|
\ 'vim-pseudocl/vim-pseudoclinstalled03 should exist'
|
||||||
|
|
||||||
|
call system('rm -rf '.g:plugs['vim-pseudocl'].dir)
|
||||||
|
PlugInstall!
|
||||||
|
q
|
||||||
|
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignunchanged13'),
|
||||||
|
\ 'vim-easy-align/vim-easy-alignunchanged13 should exist'
|
||||||
|
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled13'),
|
||||||
|
\ 'vim-pseudocl/vim-pseudoclinstalled13 should exist'
|
||||||
|
|
||||||
|
call system('cd '.g:plugs['vim-easy-align'].dir.' && git reset --hard HEAD^')
|
||||||
|
PlugUpdate!
|
||||||
|
q
|
||||||
|
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated13'),
|
||||||
|
\ 'vim-easy-align/vim-easy-alignupdated13 should exist'
|
||||||
|
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclunchanged13'),
|
||||||
|
\ 'vim-pseudocl/vim-pseudoclunchanged13 should exist'
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
~ Overriding `dir`
|
~ Overriding `dir`
|
||||||
|
Loading…
Reference in New Issue
Block a user