diff --git a/README.md b/README.md index 8376f28..3a2a791 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,18 @@ see [`:h vundle`](vundle/blob/master/doc/vundle.txt#L1) vimdoc for more details. See [gmarik's vimrc](https://github.com/gmarik/vimfiles/blob/1f4f26d42f54443f1158e0009746a56b9a28b053/vimrc#L136) for working example. +## FAQ + +- **Q** i'm aked for username/pass, why? + **A** Correct invalid bundle name. + this is the case of invalid name used with `Bundle`, which leads to attemt to clone nonexisting repo: + + git clone http://github.com/gmarik/non_existin_repo + Cloning into non_existin_repo... + Username: + Password: + fatal: Authentication failed + ## Contributors * [redlinesoftware](http://redlinesoftware.com) - for lending me 24" monitor! diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 1ef7123..df2e3ac 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -4,8 +4,8 @@ " Readme: http://github.com/gmarik/vundle/blob/master/README.md " Version: 0.8 -com! -nargs=+ Bundle -\ call vundle#config#bundle() +com! -nargs=+ -bang Bundle +\ call vundle#config#bundle('!' == '', ) com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall \ call vundle#installer#install('!' == '', ) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 9d761ee..9730e4d 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -1,5 +1,5 @@ -func! vundle#config#bundle(arg, ...) - let bundle = vundle#config#init_bundle(a:arg, a:000) +func! vundle#config#bundle(bang, arg, ...) abort + let bundle = vundle#config#init_bundle(a:bang, a:arg, a:000) call s:rtp_rm_a() call add(g:vundle#bundles, bundle) call s:rtp_add_a() @@ -22,20 +22,25 @@ func! vundle#config#require(bundles) abort endfor endf -func! vundle#config#init_bundle(name, opts) - let opts = extend(s:parse_options(a:opts), s:parse_name(substitute(a:name,"['".'"]\+','','g'))) +func! vundle#config#init_bundle(bang, name, opts) + let opts = extend(s:parse_options(a:bang, a:opts), s:parse_name(substitute(a:name,"['".'"]\+','','g')),'keep') return extend(opts, copy(s:bundle)) endf -func! s:parse_options(opts) - " TODO: improve this - if len(a:opts) != 1 | return {} | endif +func! s:parse_options(bang, opts) + if len(a:opts) != 1 + let opts = {} + elseif type(a:opts[0]) == type({}) + let opts = a:opts[0] + elseif type(a:opts[0]) == type('') + let opts = {'rev': a:opts[0]} + endif - if type(a:opts[0]) == type({}) - return a:opts[0] - else - return {'rev': a:opts[0]} + if a:bang + let opts = extend({'sync':'no'}, opts) endif + + return opts endf func! s:parse_name(arg) @@ -47,6 +52,7 @@ func! s:parse_name(arg) elseif arg =~? '^\s*\(git@\|git://\)\S\+' \ || arg =~? '(file|https\?)://' \ || arg =~? '\.git\s*$' + \ || isdirectory(expand(arg)) let uri = arg let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1] else @@ -76,7 +82,20 @@ endf let s:bundle = {} +func! s:bundle.nosync() + return has_key(self, 'sync') && 'no' == self.sync +endf + +func! s:bundle.installed() + return !empty(split(globpath(self.path(), '*'), "\n")) +endf + func! s:bundle.path() + " TODO: should lcd to tmpdir here + if self.nosync() && isdirectory(expand(self.uri)) + return self.uri + endif + return join([g:vundle#bundle_dir, self.name], '/') endf diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index de72428..b13de3d 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -1,4 +1,5 @@ func! vundle#installer#install(bang, ...) abort + if !isdirectory(g:vundle#bundle_dir) | call mkdir(g:vundle#bundle_dir, 'p') | endif let bundles = (a:1 == '') ? \ s:reload_bundles() : \ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})') @@ -87,12 +88,10 @@ func! s:helptags(rtp) abort helptags `=a:rtp.'/doc/'` endf -func! s:installed(bundle) abort - return !empty(split(globpath(a:bundle.path(), '*'), "\n")) -endf -func! vundle#installer#sync(bang, bundle) abort - if s:installed(a:bundle) +func! s:sync(bang, bundle) abort + if a:bundle.nosync() | return a:bang | endif + if a:bundle.installed() if !(a:bang) | return 0 | endif let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull' else diff --git a/test/plugin/test_plugin.vim b/test/plugin/test_plugin.vim new file mode 100644 index 0000000..98db346 --- /dev/null +++ b/test/plugin/test_plugin.vim @@ -0,0 +1,3 @@ +func! g:vundle_test_plugin() + return 'ok' +endf diff --git a/test/vimrc b/test/vimrc index 28362a3..b2ec0c5 100644 --- a/test/vimrc +++ b/test/vimrc @@ -1,6 +1,10 @@ " vim -u test/vimrc set nocompatible +syntax on + +silent exec 'e '.expand('') + filetype off runtime macros/matchit.vim set rtp+=~/.vim/vundle.git/ @@ -34,19 +38,59 @@ Bundle 'rstacruz/sparkup.git', {'rtp': 'vim/'} " Camel case Bundle 'vim-scripts/RubySinatra' + " PostInstall Bundle 'wincent/Command-T' +" NOSYNC +" existing directory +Bundle! '~/.vim/vundle.git/test/' + +" just create one +Bundle! 'a_plugin' +" +" just create one, and override name +Bundle! 'b_plugin', {'name': 'zzz'} + filetype plugin indent on " Automatically detect file types. set wildignore+=doc " should not break helptags -func! s:assert_bundles() abort +augroup vimrc + au WinEnter * call Test() +augroup END + +func! Test() abort + if 'ok' != g:vundle_test_plugin() + throw 'ooops' + endif + + call Assert_bundles() + call Assert_a_bundle() + call Assert_b_bundle() +endf + +func! Assert(cond, msg) + if !(a:cond) + throw a:msg + endif +endf + +func! Assert_bundles() abort for b in g:vundle#bundles - if (!isdirectory(b.path().'/.git')) - throw b.name.' not installed' - endif + call Assert(b.nosync() || b.installed(), b.name.' not installed') endfor endf -call s:assert_bundles() +func! Assert_a_bundle() abort + let b = filter(copy(g:vundle#bundles), 'v:val.name == "a_plugin"')[0] + let c = (b.path() == expand(g:vundle#bundle_dir.'/'.'a_plugin')) + call Assert(c, b.name.' isnt instaled') +endf + +func! Assert_b_bundle() abort + let b = filter(copy(g:vundle#bundles), 'v:val.name == "zzz"')[0] + let c = (b.path() == expand(g:vundle#bundle_dir.'/'.'zzz')) + call Assert(c, b.name.' isnt instaled') +endf +