From d5d22e29ca749a14a9d95d91909c79209353a7cc Mon Sep 17 00:00:00 2001 From: Marwan Al Jubeh Date: Tue, 29 Nov 2011 00:13:03 +0200 Subject: [PATCH] Properly update/sync existing submodules. Also, refactored the sync method. --- autoload/vundle/installer.vim | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index b3c3579..16b13bf 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -206,24 +206,30 @@ endf func! s:sync(bang, bundle) abort let git_dir = expand(a:bundle.path().'/.git/', 1) - if isdirectory(git_dir) - if !(a:bang) | return 'todate' | endif - let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull' - if (has('win32') || has('win64')) - let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives - let cmd = '"'.cmd.'"' " enclose in quotes + call s:system('cd '.shellescape(g:bundle_dir).' && git status') + if v:shell_error + if isdirectory(git_dir) + if !(a:bang) | return 'todate' | endif + let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull' + else + let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) endif else - call s:system('cd '.shellescape(g:bundle_dir).'; git status') - if v:shell_error - let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) + let top_level = substitute(s:system('cd '.shellescape(g:bundle_dir).' && git rev-parse --show-toplevel'), '\n', '', 'g') + let prefix = substitute(s:system('cd '.shellescape(g:bundle_dir).' && git rev-parse --show-prefix'), '\n', '', 'g') + let relative_path = prefix.substitute(a:bundle.path(), g:bundle_dir.'/', '', '') + if isdirectory(git_dir) + if !(a:bang) | return 'todate' | endif + let cmd = 'cd '.shellescape(top_level).' && git submodule update '.shellescape(relative_path) else - let top_level = substitute(s:system('cd '.shellescape(g:bundle_dir).'; git rev-parse --show-toplevel'), '\n', '', 'g') - let prefix = substitute(s:system('cd '.shellescape(g:bundle_dir).'; git rev-parse --show-prefix'), '\n', '', 'g') - let relative_path = prefix.substitute(a:bundle.path(), g:bundle_dir.'/', '', '') - let cmd = 'cd '.shellescape(top_level).'; git submodule add '.a:bundle.uri.' '.shellescape(relative_path).'; git submodule init' + let cmd = 'cd '.shellescape(top_level).' && git submodule add '.a:bundle.uri.' '.shellescape(relative_path).' && git submodule init' endif + end + + if (has('win32') || has('win64')) + let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives + let cmd = '"'.cmd.'"' " enclose in quotes endif let out = s:system(cmd)