Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more DVCS support #134

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions autoload/vundle/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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())')
Expand Down
54 changes: 45 additions & 9 deletions autoload/vundle/installer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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