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

Let the site a short form URL gets expanded into be customised #90

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
41 changes: 35 additions & 6 deletions plugin/minpac.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@ endfunction

" Initialize minpac.
function! minpac#init(...) abort
let l:opt = extend(copy(get(a:000, 0, {})),
\ {'dir': '', 'package_name': 'minpac', 'git': 'git', 'depth': 1, 'jobs': 8, 'verbose': 2, 'status_open': 'vertical'}, 'keep')
let l:opt = extend(
\ copy(get(a:000, 0, {})),
\ {
\ 'dir': '',
\ 'package_name': 'minpac',
\ 'git': 'git',
\ 'depth': 1,
\ 'jobs': 8,
\ 'verbose': 2,
\ 'status_open': 'vertical',
\ 'site': 'github',
\ 'sites': {
\ 'github': 'https://github.com/',
\ 'gitlab': 'https://gitlab.com/',
\ 'bitbucket': 'https://bitbucket.com/'
\ }
\ },
\ 'keep'
\ )

let g:minpac#opt = l:opt
let g:minpac#pluglist = {}
Expand Down Expand Up @@ -60,13 +77,25 @@ endfunction
" Register the specified plugin.
function! minpac#add(plugname, ...) abort
call s:ensure_initialization()
let l:opt = extend(copy(get(a:000, 0, {})),
\ {'name': '', 'type': 'start', 'depth': g:minpac#opt.depth,
\ 'frozen': 0, 'branch': '', 'rev': '', 'do': ''}, 'keep')
let l:opt = extend(
\ copy(get(a:000, 0, {})),
\ {
\ 'name': '',
\ 'type': 'start',
\ 'depth': g:minpac#opt.depth,
\ 'frozen': 0,
\ 'branch': '',
\ 'rev': '',
\ 'do': '',
\ 'site': g:minpac#opt.site
\ },
\ 'keep'
\ )

" URL
if a:plugname =~? '^[-._0-9a-z]\+\/[-._0-9a-z]\+$'
let l:opt.url = 'https://github.com/' . a:plugname . '.git'
let l:url = g:minpac#opt.sites[l:opt.site]
let l:opt.url = l:url . a:plugname . '.git'
else
let l:opt.url = a:plugname
endif
Expand Down
11 changes: 10 additions & 1 deletion test/test_minpac.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ func Test_minpac_init()
call assert_equal(8, g:minpac#opt.jobs)
call assert_equal(2, g:minpac#opt.verbose)
call assert_equal('vertical', g:minpac#opt.status_open)
call assert_equal('github', g:minpac#opt.site)
call assert_equal({'github': 'https://github.com/', 'gitlab': 'https://gitlab.com/', 'bitbucket': 'https://bitbucket.com/'}, g:minpac#opt.sites)
call assert_equal({}, minpac#getpluglist())

let g:minpac#pluglist.foo = 'bar'

" Change settings
call minpac#init({'package_name': 'm', 'git': 'foo', 'depth': 10, 'jobs': 2, 'verbose': 1, 'status_open': 'horizontal'})
call minpac#init({'package_name': 'm', 'git': 'foo', 'depth': 10, 'jobs': 2, 'verbose': 1, 'status_open': 'horizontal', 'site': 'foohub', 'sites': {'foohub': 'https://foohub.com/'}})
call assert_true(isdirectory('pack/m/start'))
call assert_true(isdirectory('pack/m/opt'))
call assert_equal('foo', g:minpac#opt.git)
call assert_equal(10, g:minpac#opt.depth)
call assert_equal(2, g:minpac#opt.jobs)
call assert_equal(1, g:minpac#opt.verbose)
call assert_equal('horizontal', g:minpac#opt.status_open)
call assert_equal('foohub', g:minpac#opt.site)
call assert_equal({'foohub': 'https://foohub.com/'}, g:minpac#opt.sites)
call assert_equal({}, minpac#getpluglist())

call delete('pack', 'rf')
Expand Down Expand Up @@ -70,6 +74,11 @@ func Test_minpac_add()
call assert_equal('', p.do)
call assert_equal('abcdef', p.rev)

" Different site
call minpac#add('k-takata/minpac', {'site': 'bitbucket'})
let p = minpac#getpluginfo('minpac')
call assert_equal('https://bitbucket.com/k-takata/minpac.git', p.url)

" SSH URL
call minpac#add('[email protected]:k-takata/minpac.git', {'name': 'm'})
let p = minpac#getpluginfo('m')
Expand Down