From f84b02e635c0d6cd7bdbb8fb07bb1b4f016475d4 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 00:52:27 -0500 Subject: [PATCH 1/7] handle errors - do not redraw on errors - echo error during installation --- autoload/vundle/installer.vim | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 3edbccf..e0b8ee2 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -4,8 +4,8 @@ func! vundle#installer#install(bang, ...) abort \ s:reload_bundles() : \ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})') - let installed = s:install(a:bang, bundles) - redraw! + let [installed, errors] = s:install(a:bang, bundles) + if empty(errors) | redraw! | end " TODO: handle error: let user know hen they need to restart Vim call vundle#config#require(bundles) @@ -78,12 +78,27 @@ func! s:sync(bang, bundle) abort else let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) endif + silent exec '!'.cmd - return 1 + + if 0 != v:shell_error + echohl Error | echo 'Error installing "'.a:bundle.name.'". Failed cmd: '.cmd | echohl None + return v:shell_error + end + return 0 endf func! s:install(bang, bundles) abort - return filter(copy(a:bundles), 's:sync(a:bang, v:val)') + let [installed, errors] = [[],[]] + + for b in a:bundles + if 0 == s:sync(a:bang, b) + if a:bang | call add(installed, b) | endif + else + call add(errors, b) + endif + endfor + return [installed, errors] endf " TODO: make it pause after output in console mode From 46d6ac3dfbbd739bd9b3975b476e27d8f13e0d01 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 00:53:19 -0500 Subject: [PATCH 2/7] Improved log message --- autoload/vundle/installer.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index e0b8ee2..4fdb225 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -9,9 +9,11 @@ func! vundle#installer#install(bang, ...) abort " TODO: handle error: let user know hen they need to restart Vim call vundle#config#require(bundles) - call s:log("Installed bundles:\n".join((empty(installed) ? - \ ['no new bundles installed'] : - \ map(installed, 'v:val.name')),"\n")) + let msg = 'No new bundles were installed' + if (!empty(installed)) + let msg = "Installed bundles:\n".join(map(installed, 'v:val.name'),"\n") + endif + call s:log(msg) call vundle#installer#helptags(bundles) endf @@ -21,7 +23,7 @@ func! vundle#installer#helptags(bundles) abort let help_dirs = filter(bundle_dirs, 's:has_doc(v:val)') call map(copy(help_dirs), 's:helptags(v:val)') if !empty(help_dirs) - call s:log('Helptags: done. '.len(help_dirs).' bundles processed') + call s:log('Helptags: '.len(help_dirs).' bundles processed') endif return help_dirs endf From 2067c2fc6207341a7b650f6ea834cc4b4ce41b32 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 01:24:18 -0500 Subject: [PATCH 3/7] Handle script fetching errors - make curl --fail on HTTP errors - make curl -o output to file - handle erros - silence curl output - unify curl command --- autoload/vundle/scripts.vim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index d949c91..89b2eb4 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -60,24 +60,26 @@ func! s:display(headers, results) endf func! s:fetch_scripts(to) - let temp = shellescape(tempname()) - if has('win32') || has('win64') - let scripts_dir = fnamemodify(expand(a:to), ":h") - if !isdirectory(scripts_dir) - call mkdir(scripts_dir, "p") - endif - exec '!curl http://vim-scripts.org/api/scripts.json > '.temp. - \ '&& move /Y '.temp.' '.shellescape(a:to) - else - exec '!curl http://vim-scripts.org/api/scripts.json > '.temp. - \ '&& mkdir -p $(dirname '.shellescape(a:to).') && mv -f '.temp.' '.shellescape(a:to) + let scripts_dir = fnamemodify(expand(a:to), ":h") + if !isdirectory(scripts_dir) + call mkdir(scripts_dir, "p") endif + + silent exec '!curl --fail -s -o '.shellescape(a:to).' http://vim-scripts.org/api/scripts.json' + + if (0 != v:shell_error) + echoerr 'Error fetching scripts!' + return v:shell_error + endif + return 0 endf func! s:load_scripts(bang) let f = expand('$HOME/.vim-vundle/vim-scripts.org.json') if a:bang || !filereadable(f) - call s:fetch_scripts(f) + if 0 != s:fetch_scripts(f) + return [] + end endif return eval(readfile(f, 'b')[0]) endf From 800968259150e74a5da0bb4f842c45750f881675 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 01:39:11 -0500 Subject: [PATCH 4/7] improve message disaplay --- autoload/vundle/scripts.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index 89b2eb4..93a98ca 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -12,6 +12,7 @@ func! vundle#scripts#all(bang, ...) setl hls let b:match = a:1 endif + redraw! echo len(matches).' bundles found' endf From b75036a8e3514b7b0f9859ea8b95ee4d5651dbae Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 01:56:46 -0500 Subject: [PATCH 5/7] improve message - add status to return values - check status to see if bundle installed --- autoload/vundle/installer.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 4fdb225..bcd735e 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -70,7 +70,7 @@ endf func! s:sync(bang, bundle) abort let git_dir = expand(a:bundle.path().'/.git/') if isdirectory(git_dir) - if !(a:bang) | return 0 | endif + if !(a:bang) | return [0, 'skip'] | endif let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull' if (has('win32') || has('win64')) @@ -85,17 +85,18 @@ func! s:sync(bang, bundle) abort if 0 != v:shell_error echohl Error | echo 'Error installing "'.a:bundle.name.'". Failed cmd: '.cmd | echohl None - return v:shell_error + return [v:shell_error, 'error'] end - return 0 + return [0, 'ok'] endf func! s:install(bang, bundles) abort let [installed, errors] = [[],[]] for b in a:bundles - if 0 == s:sync(a:bang, b) - if a:bang | call add(installed, b) | endif + let err_code, status = s:sync(a:bang, b) + if 0 == err_code + if 'ok' == status | call add(installed, b) | endif else call add(errors, b) endif From 3849b5b8a62c69a855830cfc1f52983d94a34fd8 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 01:58:34 -0500 Subject: [PATCH 6/7] fix err --- autoload/vundle/installer.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index bcd735e..a226092 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -94,7 +94,7 @@ func! s:install(bang, bundles) abort let [installed, errors] = [[],[]] for b in a:bundles - let err_code, status = s:sync(a:bang, b) + let [err_code, status] = s:sync(a:bang, b) if 0 == err_code if 'ok' == status | call add(installed, b) | endif else From 560426c4a459c0c5099a9d4dded9b0a91d86f7c6 Mon Sep 17 00:00:00 2001 From: gmarik Date: Fri, 15 Jul 2011 02:08:01 -0500 Subject: [PATCH 7/7] test invalid bundle aswell --- test/vimrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/vimrc b/test/vimrc index ac33de1..d0ff49c 100644 --- a/test/vimrc +++ b/test/vimrc @@ -30,6 +30,9 @@ Bundle 'vim-scripts/ragtag.vim' Bundle 'altercation/vim-colors-solarized' " with extension Bundle 'nelstrom/vim-mac-classic-theme.git' +" +" invalid uri +Bundle 'nonexistinguser/yupppierepo.git' " full uri Bundle 'https://github.com/vim-scripts/vim-game-of-life'