diff --git a/.travis.yml b/.travis.yml index 5fc0240..028ca78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ env: - PATH=$DEPS/bin:$PATH matrix: include: - - env: ENV=vim72 + - env: ENV=vim74 rvm: 1.8.7 addons: { apt: { packages: [vim-nox] } } - env: ENV=python @@ -26,7 +26,7 @@ install: | git config --global user.email "you@example.com" git config --global user.name "Your Name" - if [ "$ENV" == "vim72" ]; then + if [ "$ENV" == "vim74" ]; then mkdir -p ${DEPS}/bin ln -s /usr/bin/vim.nox ${DEPS}/bin/vim return diff --git a/plug.vim b/plug.vim index 2475fb4..f7c4444 100644 --- a/plug.vim +++ b/plug.vim @@ -96,7 +96,7 @@ let s:plug_src = 'https://github.com/junegunn/vim-plug.git' let s:plug_tab = get(s:, 'plug_tab', -1) let s:plug_buf = get(s:, 'plug_buf', -1) let s:mac_gui = has('gui_macvim') && has('gui_running') -let s:is_win = has('win32') || has('win64') +let s:is_win = has('win32') let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win) let s:vim8 = has('patch-8.0.0039') && exists('*job_start') let s:me = resolve(expand(':p')) @@ -194,6 +194,14 @@ function! s:ask_no_interrupt(...) endtry endfunction +function! s:lazy(plug, opt) + return has_key(a:plug, a:opt) && + \ (empty(s:to_a(a:plug[a:opt])) || + \ !isdirectory(a:plug.dir) || + \ len(s:glob(s:rtp(a:plug), 'plugin')) || + \ len(s:glob(s:rtp(a:plug), 'after/plugin'))) +endfunction + function! plug#end() if !exists('g:plugs') return s:err('Call plug#begin() first') @@ -215,7 +223,7 @@ function! plug#end() continue endif let plug = g:plugs[name] - if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for') + if get(s:loaded, name, 0) || !s:lazy(plug, 'on') && !s:lazy(plug, 'for') let s:loaded[name] = 1 continue endif @@ -811,6 +819,9 @@ function! s:prepare(...) execute 'silent! unmap ' k endfor setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline modifiable nospell + if exists('+colorcolumn') + setlocal colorcolumn= + endif setf vim-plug if exists('g:syntax_on') call s:syntax() @@ -1056,6 +1067,8 @@ function! s:update_impl(pull, force, args) abort let s:clone_opt .= ' -c core.eol=lf -c core.autocrlf=input' endif + let s:submodule_opt = s:git_version_requirement(2, 8) ? ' --jobs='.threads : '' + " Python version requirement (>= 2.7) if python && !has('python3') && !ruby && !use_job && s:update.threads > 1 redir => pyv @@ -1147,7 +1160,7 @@ function! s:update_finish() if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && \ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir)) call s:log4(name, 'Updating submodules. This may take a while.') - let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir) + let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir) endif let msg = s:format_message(v:shell_error ? 'x': '-', name, out) if v:shell_error @@ -1366,7 +1379,7 @@ while 1 " Without TCO, Vim stack is bound to explode let name = keys(s:update.todo)[0] let spec = remove(s:update.todo, name) - let new = !isdirectory(spec.dir) + let new = empty(globpath(spec.dir, '.git', 1)) call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') redraw @@ -2259,7 +2272,7 @@ function! s:upgrade() let new = tmp . '/plug.vim' try - let out = s:system(printf('git clone --depth 1 %s %s', s:plug_src, tmp)) + let out = s:system(printf('git clone --depth 1 %s %s', s:shellesc(s:plug_src), s:shellesc(tmp))) if v:shell_error return s:err('Error upgrading vim-plug: '. out) endif @@ -2455,7 +2468,11 @@ function! s:diff() call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') for [k, v] in plugs let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' - let diff = s:system_chomp('git log --graph --color=never '.join(map(['--pretty=format:%x01%h%x01%d%x01%s%x01%cr', range], 's:shellesc(v:val)')), v.dir) + let cmd = 'git log --graph --color=never '.join(map(['--pretty=format:%x01%h%x01%d%x01%s%x01%cr', range], 's:shellesc(v:val)')) + if has_key(v, 'rtp') + let cmd .= ' -- '.s:shellesc(v.rtp) + endif + let diff = s:system_chomp(cmd, v.dir) if !empty(diff) let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) @@ -2474,8 +2491,13 @@ function! s:diff() \ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : '')) if cnts[0] || cnts[1] - nnoremap :silent! call preview_commit() - nnoremap o :silent! call preview_commit() + nnoremap (plug-preview) :silent! call preview_commit() + if empty(maparg("\", 'n')) + nmap (plug-preview) + endif + if empty(maparg('o', 'n')) + nmap o (plug-preview) + endif endif if cnts[0] nnoremap X :call revert() diff --git a/test/regressions.vader b/test/regressions.vader index dd2a6a2..40f6d4b 100644 --- a/test/regressions.vader +++ b/test/regressions.vader @@ -41,6 +41,7 @@ Execute (#130 Proper cleanup of on-demand loading triggers): Plug 'junegunn/vim-emoji', { 'on': ['EmojiCommand', 'EmojiCommand2', '(EmojiMapping)'] } call plug#end() PlugInstall | q + call mkdir(g:plugs['vim-emoji'].dir.'/after/plugin', 'p') Assert exists(':EmojiCommand'), 'EmojiCommand not defined' Assert exists(':EmojiCommand2'), 'EmojiCommand2 not defined' diff --git a/test/run b/test/run index 92efc3b..2ddfd7e 100755 --- a/test/run +++ b/test/run @@ -91,7 +91,7 @@ DOC echo "let g:plug_config_vader_test = 1" > "$TEMP/configs/yyy.vim" rm -rf "$PLUG_FIXTURES/ftplugin-msg" - mkdir -p "$PLUG_FIXTURES/ftplugin-msg/ftplugin" + mkdir -p "$PLUG_FIXTURES"/ftplugin-msg/{plugin,ftplugin} echo "echomsg 'ftplugin-c'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/c.vim" echo "echomsg 'ftplugin-java'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/java.vim" diff --git a/test/workflow.vader b/test/workflow.vader index 269a884..5275bf2 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -370,8 +370,15 @@ Execute (New commits on remote, PlugUpdate, then PlugDiff): AssertEqual 1, &previewwindow AssertEqual 'git', &filetype - " Back to plug window - wincmd p + " Close preview window + pclose + + " Open and go to preview window with a custom mapping + nmap (plug-preview)P + execute "normal \" + AssertEqual 1, &previewwindow, 'Should be on preview window' + normal q + AssertEqual 0, &previewwindow, 'Should not be on preview window' " ]] motion execute 'normal $]]' @@ -530,6 +537,51 @@ Execute (PlugDiff): Assert !empty(mapcheck("\")) q +Execute (Do not show diff for commits outside of rtp): + call plug#begin() + call plug#end() + PlugClean! + + call plug#begin() + Plug 'file://'.expand('$PLUG_FIXTURES').'/xxx' + Plug 'file://'.expand('$PLUG_FIXTURES').'/yyy', { 'rtp': 'rtp' } + call plug#end() + PlugInstall + Log getline(1, '$') + + call system('cd "$PLUG_FIXTURES/xxx" && git commit --allow-empty -m update-xxx && git tag -f xxx') + call system('cd "$PLUG_FIXTURES/yyy" && git commit --allow-empty -m update-yyy && git tag -f yyy') + + let g:plugs.yyy.tag = 'yyy' + PlugUpdate + Log getline(1, '$') + + PlugDiff + " 1 plugin(s) updated. + " [==] + " + " Last update: + " ------------ + " + " - xxx: + " * 7faa9b2 update-xxx (0 seconds ago) + " + " Pending updates: + " ---------------- + " + " N/A + " + Log getline(1, '$') + AssertEqual 14, line('$') + AssertEqual '1 plugin(s) updated.', getline(1) + AssertEqual '[==]', getline(2) + AssertEqual 'Last update:', getline(4) + AssertEqual '- xxx:', getline(7) + Assert !empty(mapcheck('o')) + Assert !empty(mapcheck('X')) + Assert !empty(mapcheck("\")) + q + ********************************************************************** ~ On-demand loading / Partial installation/update ~ ********************************************************************** @@ -1504,7 +1556,7 @@ Execute (Commit hash support): Log getline(1, '$') AssertEqual 'x goyo.vim:', getline(5) AssertEqual ' fatal: invalid reference: ffffffff', getline(6) - AssertEqual 0, stridx(getline(7), '- vim-emoji: HEAD is now at 9db7fcf...') + AssertEqual 0, stridx(getline(7), '- vim-emoji: HEAD is now at 9db7fcf') let hash = system(printf('cd %s && git rev-parse HEAD', g:plugs['vim-emoji'].dir))[:-2] AssertEqual '9db7fcfee0d90dafdbcb7a32090c0a9085eb054a', hash @@ -1674,3 +1726,15 @@ Execute (PlugConfig shall load config automatically): redir => out AssertEqual 1, exists('g:plug_config_vader_test'), 'Variable has not been set by config' redir END + +Execute (#766 - Allow cloning into an empty directory): + let d = '/tmp/vim-plug-test/goyo-already' + call system('rm -rf ' . d) + call mkdir(d) + call plug#begin() + Plug 'junegunn/goyo.vim', { 'dir': d } + call plug#end() + PlugInstall + AssertExpect! '[=]', 1 + q + unlet d