don't error out early, if git not exists
Even if git is not available, one can still use plug.vim for managing the runtime path. This allows, to share the same config with several vim instances, some of which, might not have vim installed (or not have it in $PATH). The commands `:Plug` and `:PlugClean` seem to be safe even in this case. Unfortunately in that case, plug.vim errors out on every start. So let's just move the check for the existance of git to the place, where it is actually needed. In theory, we can also just move the check `:if excutable('git')` around the definition of the all commands that need git, so they would be only defined on systems that have git installed. But I actually like the way, how the commands will always be defined, but they error out once one tries to execute them.
This commit is contained in:
parent
c88ab60007
commit
d85465cb7e
27
plug.vim
27
plug.vim
|
@ -112,14 +112,17 @@ function! plug#begin(...)
|
|||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:define_commands()
|
||||
command! -nargs=+ -bar Plug call s:add(<args>)
|
||||
function! s:git_exists()
|
||||
if !executable('git')
|
||||
return s:err('`git` executable not found. vim-plug requires git.')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:define_commands()
|
||||
command! -nargs=+ -bar Plug call s:add(<args>)
|
||||
command! -nargs=0 -bar -bang PlugClean call s:clean(<bang>0)
|
||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(<bang>0, [<f-args>])
|
||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(<bang>0, [<f-args>])
|
||||
command! -nargs=0 -bar -bang PlugClean call s:clean(<bang>0)
|
||||
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif
|
||||
command! -nargs=0 -bar PlugStatus call s:status()
|
||||
command! -nargs=0 -bar PlugDiff call s:diff()
|
||||
|
@ -776,6 +779,10 @@ function! s:names(...)
|
|||
endfunction
|
||||
|
||||
function! s:update_impl(pull, force, args) abort
|
||||
if !s:git_exists()
|
||||
return
|
||||
endif
|
||||
|
||||
let args = copy(a:args)
|
||||
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||
\ remove(args, -1) : get(g:, 'plug_threads', 16)
|
||||
|
@ -1847,6 +1854,10 @@ function! s:clean(force)
|
|||
endfunction
|
||||
|
||||
function! s:upgrade()
|
||||
if !s:git_exists()
|
||||
return
|
||||
endif
|
||||
|
||||
echo 'Downloading the latest version of vim-plug'
|
||||
redraw
|
||||
let tmp = tempname()
|
||||
|
@ -1880,6 +1891,9 @@ function! s:upgrade_specs()
|
|||
endfunction
|
||||
|
||||
function! s:status()
|
||||
if !s:git_exists()
|
||||
return
|
||||
endif
|
||||
call s:prepare()
|
||||
call append(0, 'Checking plugins')
|
||||
call append(1, '')
|
||||
|
@ -2012,6 +2026,9 @@ function! s:append_ul(lnum, text)
|
|||
endfunction
|
||||
|
||||
function! s:diff()
|
||||
if !s:git_exists()
|
||||
return
|
||||
endif
|
||||
call s:prepare()
|
||||
call append(0, ['Collecting changes ...', ''])
|
||||
let cnts = [0, 0]
|
||||
|
@ -2071,6 +2088,9 @@ function! s:revert()
|
|||
endfunction
|
||||
|
||||
function! s:snapshot(force, ...) abort
|
||||
if !s:git_exists()
|
||||
return
|
||||
endif
|
||||
call s:prepare()
|
||||
setf vim
|
||||
call append(0, ['" Generated by vim-plug',
|
||||
|
@ -2117,4 +2137,3 @@ endif
|
|||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user