diff --git a/README.md b/README.md index 02bba7f..bcef929 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ Bundle 'git://git.wincent.com/command-t.git' " ... + " Installs bundle only if vim version matches + BundleIf '703.584', 'Valloric/YouCompleteMe' + filetype plugin indent on " required! " " Brief help diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 0bc7bf5..7d6e958 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -7,6 +7,10 @@ com! -nargs=+ Bundle \ call vundle#config#bundle() +com! -nargs=+ BundleIf +\ call vundle#config#bundle_if() + + com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall \ call vundle#installer#new('!' == '', ) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 55c7d7d..0352238 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -6,6 +6,23 @@ func! vundle#config#bundle(arg, ...) return bundle endf +func! vundle#config#bundle_if(arg, ...) + let versions = split(a:arg, '\.') + if len(versions) == 2 + if v:version == versions[0] && has(join(['patch',versions[1]],'')) + echom 'installing bundle' + echom join(a:000) + call vundle#config#bundle(join(a:000)) + endif + else + if v:version == versions[0] + echom 'installing bundle' + echom join(a:000) + call vundle#config#bundle(join(a:000)) + endif + endif +endf + func! vundle#config#init() if !exists('g:bundles') | let g:bundles = [] | endif call s:rtp_rm_a() @@ -33,11 +50,10 @@ endf func! s:parse_options(opts) " TODO: improve this if len(a:opts) != 1 | return {} | endif - if type(a:opts[0]) == type({}) return a:opts[0] else - return {'rev': a:opts[0]} + return {'rev' : a:opts[0]} endif endf diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index c4d0580..7ed65c1 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -3,7 +3,7 @@ func! vundle#installer#new(bang, ...) abort \ g:bundles : \ map(copy(a:000), 'vundle#config#bundle(v:val, {})') - let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec')) + let names = vundle#scripts#bundle_names(vundle#scripts#get_bundles()) call vundle#scripts#view('Installer',['" Installing bundles to '.expand(g:bundle_dir, 1)], names + ['Helptags']) call s:process(a:bang, (a:bang ? 'add!' : 'add')) @@ -99,8 +99,10 @@ endf func! vundle#installer#install(bang, name) abort if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif + let args = split(a:name,', ') - let b = vundle#config#init_bundle(a:name, {}) + let opts = (len(args) > 1) ? [substitute(args[1],"'",'','g')] : {} + let b = vundle#config#init_bundle(args[0], opts) return s:sync(a:bang, b) endf @@ -125,7 +127,8 @@ func! vundle#installer#helptags(bundles) abort endf func! vundle#installer#list(bang) abort - let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec')) + + let bundles = vundle#scripts#bundle_names(vundle#scripts#get_bundles()) call vundle#scripts#view('list', ['" My Bundles'], bundles) redraw echo len(g:bundles).' bundles configured' @@ -208,23 +211,46 @@ func! s:sync(bang, bundle) abort let git_dir = expand(a:bundle.path().'/.git/', 1) if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1)) if !(a:bang) | return 'todate' | endif - let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive' - let cmd = g:shellesc_cd(cmd) + let has_rev = has_key(a:bundle, 'rev') let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD' let get_current_sha = g:shellesc_cd(get_current_sha) - let initial_sha = s:system(get_current_sha)[0:15] + + if !has_rev + let cmd = 'cd '.shellescape(a:bundle.path()).' && git checkout master' + let cmd = g:shellesc_cd(cmd) + + let initial_sha = s:system(get_current_sha)[0:15] + call s:run_and_log(a:bundle, cmd) + + let on_branch = '' + else + let cmd = 'cd '.shellescape(a:bundle.path()).' && git branch --contains | grep \* | grep "no branch"' + let cmd = g:shellesc_cd(cmd) + let on_branch = s:system(cmd) + + let initial_sha = s:system(get_current_sha)[0:15] + endif + + if len(on_branch) == 0 + let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive' + let cmd = g:shellesc_cd(cmd) + endif + else let cmd = 'git clone --recursive '.shellescape(a:bundle.uri).' '.shellescape(a:bundle.path()) let initial_sha = '' endif - let out = s:system(cmd) - call s:log('') - call s:log('Bundle '.a:bundle.name_spec) - call s:log('$ '.cmd) - call s:log('> '.out) + call s:run_and_log(a:bundle, cmd) + + if has_rev + let cmd = 'cd '.shellescape(a:bundle.path()).' && git checkout '.a:bundle.rev + let cmd = g:shellesc_cd(cmd) + + call s:run_and_log(a:bundle, cmd) + endif if 0 != v:shell_error return 'error' @@ -244,6 +270,15 @@ func! s:sync(bang, bundle) abort return 'updated' endf +func! s:run_and_log(bundle, cmd) + let out = s:system(a:cmd) + + call s:log('') + call s:log('Bundle '.a:bundle.name_spec) + call s:log('$ '.a:cmd) + call s:log('> '.out) +endf + func! g:shellesc(cmd) abort if (has('win32') || has('win64')) if &shellxquote != '(' " workaround for patch #445 diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index ded6a46..58373ef 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -74,8 +74,37 @@ func! s:view_changelog() wincmd P | wincmd H endf +func! vundle#scripts#get_bundles() + "let branch_bundles = filter(copy(g:bundles), "has_key(v:val, 'branch')") + "let commit_bundles = filter(copy(g:bundles), "has_key(v:val, 'commit')") + "let tag_bundles = filter(copy(g:bundles), "has_key(v:val, 'tag')") + "let plain_bundles = filter(copy(g:bundles), "! has_key(v:val, 'tag') && ! has_key(v:val, 'commit') && ! has_key(v:val, 'branch')") + let plain_bundles = filter(copy(g:bundles), "! has_key(v:val, 'rev')") + let rev_bundles = filter(copy(g:bundles), "has_key(v:val, 'rev')") + + "let branch_bundle_names = map(copy(branch_bundles), 'printf("%s, branch:%s", v:val.name_spec, v:val.branch )') + "let commit_bundle_names = map(copy(commit_bundles), 'printf("%s, commit:%s", v:val.name_spec, v:val.commit )') + "let tag_bundle_names = map(copy(tag_bundles) , 'printf("%s, tag:%s", v:val.name_spec, v:val.tag )') + let plain_bundle_names = map(copy(plain_bundles) , 'v:val.name_spec') + let rev_bundle_names = map(copy(rev_bundles) , 'printf("%s, %s", v:val.name_spec, v:val.rev )') + + "return extend(extend(extend(plain_bundle_names, branch_bundle_names), commit_bundle_names), tag_bundle_names) + return extend(plain_bundle_names, rev_bundle_names) +endf + func! vundle#scripts#bundle_names(names) - return map(copy(a:names), ' printf("Bundle ' ."'%s'".'", v:val) ') + return map(copy(a:names), ' s:split_name(v:val) ') +endf + +func! s:split_name(name) + let split_n = split(a:name, ', ') + if len(split_n) > 1 + let ret_val = printf("Bundle '%s', '%s'", split_n[0], split_n[1]) + else + let ret_val = printf("Bundle '%s'", split_n[0]) + endif + + return ret_val endf func! vundle#scripts#view(title, headers, results)