From ac9400fa7603c9dad12c2d6baacba85e3bbd7eff Mon Sep 17 00:00:00 2001 From: Rich Alesi Date: Sun, 29 Jan 2012 03:06:57 -0500 Subject: [PATCH] hg/bzr/svn/git support --- autoload/vundle/config.vim | 56 ++++++++++++++++++++++++----------- autoload/vundle/installer.vim | 54 +++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index ee1e42b..b8a6e7a 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -40,27 +40,49 @@ func! s:parse_options(opts) endf func! s:parse_name(arg) - let arg = a:arg + let git_proto = exists('g:vundle_default_git_proto') ? g:vundle_default_git_proto : 'https' - if arg =~? '^\s*\(gh\|github\):\S\+' - \ || arg =~? '^[a-z0-9][a-z0-9-]*/[^/]\+$' - let uri = git_proto.'://github.com/'.split(arg, ':')[-1] - if uri !~? '\.git$' - let uri .= '.git' - endif - let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i') - elseif arg =~? '^\s*\(git@\|git://\)\S\+' - \ || arg =~? '\(file\|https\?\)://' - \ || arg =~? '\.git\s*$' - let uri = arg - let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1] + " default to git + let type = 'git' + + " mercurial + if a:arg[:3] ==# 'bit:' + " bit:{N}/{repo} {"type": "hg", "uri": "http://bitbucket.org/{Name}/{repo}} + let uri = 'https://bitbucket.org/'.a:arg[len('bit:'):] + let name = split(uri,'\/')[-1] + let type = 'hg' + elseif a:arg[:2]==#'hg:' + " hg:{uri} {"type": "hg", "uri": {uri}} + let uri = a:arg[len('hg:'):] + let name = split(uri,'\/')[-1] + let type = 'hg' + " bazaar + elseif a:arg[:2]==#'lp:' + let uri = a:arg + let name = split (uri, ':')[-1] + let type = 'bzr' + " git + elseif a:arg =~? '^\s*\(gh\|github\):\S\+' + \ || a:arg =~? '^[a-z0-9][a-z0-9-]*/[^/]\+$' + " github|gh:{N}/{Repo} {"type": "git", "uri": "git://github.com/{N}/{Repo}"} + let uri = git_proto.'://github.com/'.split(a:arg, ':')[-1] + if uri !~? '\.git$' + let uri .= '.git' + endif + let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i') + elseif a:arg =~? '^\s*\(git@\|git://\)\S\+' + \ || a:arg =~? '\(file\|https\?\)://' + \ || a:arg =~? '\.git\s*$' + " git|https:{uri} {"type": "git", "uri": {uri}} + let uri = a:arg + let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1] else - let name = arg - let uri = git_proto.'://github.com/vim-scripts/'.name.'.git' + let name = a:arg + let uri = git_proto.'://github.com/vim-scripts/'.name.'.git' endif - return {'name': name, 'uri': uri, 'name_spec': arg } -endf + return {'name': name, 'uri': uri, 'name_spec': a:arg, 'type':type } + endf func! s:rtp_rm_a() call filter(copy(g:bundles), 's:rtp_rm(v:val.rtpath())') diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 0f71ebf..1d863f1 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -195,17 +195,49 @@ func! s:helptags(rtp) abort 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 + + let types = {'.git' : 'git', '.hg' : 'hg', '.bzr' : 'bzr', '.svn': 'svn' } + " not sure if necessary, will detect DVCS type from directory + if empty(a:bundle.type) + for [k,t] in items(types) + let repo_dir = expand(a:bundle.path().'/.'.k.'/') + if isdirectory(repo_dir) | let type = t | break | endif + endfor + else + let type = a:bundle.type + let repo_dir = expand(a:bundle.path().'/.'.a:bundle.type.'/') + endif + + let dir = shellescape(a:bundle.path()) + + let vcs_update = { + \'git': 'cd '.dir.' && git pull', + \'hg': 'hg pull -u -R '.dir, + \'bzr': 'bzr pull -d '.dir, + \'svn': 'cd '.dir.' && svn update'} + + let vcs_checkout = { + \'git': 'git clone '.a:bundle.uri.' '.dir.'', + \'hg': 'hg clone '.a:bundle.uri.' '.dir.'', + \'bzr': 'bzr branch '.a:bundle.uri.' '.dir.'', + \'svn': ''} + + if type =~ '^\%(git\|hg\|bzr\|svn\)$' + " if folder already exists, just pull + if isdirectory(repo_dir) + if !(a:bang) | return 'todate' | endif + let cmd = vcs_update[type] + else + let cmd = vcs_checkout[type] endif else - let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) + " how did we get here? + return + endif + + if s:iswindows() + 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) @@ -234,3 +266,7 @@ func! s:log(str) abort call add(g:vundle_log, '['.strftime(fmt).'] '.a:str) return a:str endf + +func! s:iswindows() abort + return has("win16") || has("win32") || has("win64") +endf