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

Added commit/tag/branch lock #267

Closed
wants to merge 9 commits into from
3 changes: 1 addition & 2 deletions autoload/vundle/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ endf
func! s:parse_options(opts)
" TODO: improve this
if len(a:opts) != 1 | return {} | endif

if type(a:opts[0]) == type({})
return a:opts[0]
else
return {'rev': a:opts[0]}
return {'rev' : a:opts[0]}
endif
endf

Expand Down
57 changes: 46 additions & 11 deletions autoload/vundle/installer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ func! vundle#installer#new(bang, ...) abort
\ g:bundles :
\ map(copy(a:000), 'vundle#config#bundle(v:val, {})')

let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
let names = vundle#scripts#bundle_names(vundle#scripts#get_bundles())
call vundle#scripts#view('Installer',['" Installing bundles to '.expand(g:bundle_dir, 1)], names + ['Helptags'])

call s:process(a:bang, (a:bang ? 'add!' : 'add'))
Expand Down Expand Up @@ -99,8 +99,10 @@ endf

func! vundle#installer#install(bang, name) abort
if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
let args = split(a:name,', ')

let b = vundle#config#init_bundle(a:name, {})
let opts = (len(args) > 1) ? [substitute(args[1],"'",'','g')] : {}
let b = vundle#config#init_bundle(args[0], opts)

return s:sync(a:bang, b)
endf
Expand All @@ -125,7 +127,8 @@ func! vundle#installer#helptags(bundles) abort
endf

func! vundle#installer#list(bang) abort
let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))

let bundles = vundle#scripts#bundle_names(vundle#scripts#get_bundles())
call vundle#scripts#view('list', ['" My Bundles'], bundles)
redraw
echo len(g:bundles).' bundles configured'
Expand Down Expand Up @@ -208,23 +211,46 @@ func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/', 1)
if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1))
if !(a:bang) | return 'todate' | endif
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'

let cmd = g:shellesc_cd(cmd)
let has_rev = has_key(a:bundle, 'rev')

let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = g:shellesc_cd(get_current_sha)
let initial_sha = s:system(get_current_sha)[0:15]

if !has_rev
let cmd = 'cd '.shellescape(a:bundle.path()).' && git checkout master'
let cmd = g:shellesc_cd(cmd)

let initial_sha = s:system(get_current_sha)[0:15]
call s:run_and_log(a:bundle, cmd)

let on_branch = ''
else
let cmd = 'cd '.shellescape(a:bundle.path()).' && git branch --contains | grep \* | grep "no branch"'
let cmd = g:shellesc_cd(cmd)
let on_branch = s:system(cmd)

let initial_sha = s:system(get_current_sha)[0:15]
endif

if len(on_branch) == 0
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = g:shellesc_cd(cmd)
endif

else
let cmd = 'git clone --recursive '.shellescape(a:bundle.uri).' '.shellescape(a:bundle.path())
let initial_sha = ''
endif

let out = s:system(cmd)
call s:log('')
call s:log('Bundle '.a:bundle.name_spec)
call s:log('$ '.cmd)
call s:log('> '.out)
call s:run_and_log(a:bundle, cmd)

if has_rev
let cmd = 'cd '.shellescape(a:bundle.path()).' && git checkout '.a:bundle.rev
let cmd = g:shellesc_cd(cmd)

call s:run_and_log(a:bundle, cmd)
endif

if 0 != v:shell_error
return 'error'
Expand All @@ -244,6 +270,15 @@ func! s:sync(bang, bundle) abort
return 'updated'
endf

func! s:run_and_log(bundle, cmd)
let out = s:system(a:cmd)

call s:log('')
call s:log('Bundle '.a:bundle.name_spec)
call s:log('$ '.a:cmd)
call s:log('> '.out)
endf

func! g:shellesc(cmd) abort
if (has('win32') || has('win64'))
if &shellxquote != '(' " workaround for patch #445
Expand Down
31 changes: 30 additions & 1 deletion autoload/vundle/scripts.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,37 @@ func! s:view_changelog()
wincmd P | wincmd H
endf

func! vundle#scripts#get_bundles()
"let branch_bundles = filter(copy(g:bundles), "has_key(v:val, 'branch')")
"let commit_bundles = filter(copy(g:bundles), "has_key(v:val, 'commit')")
"let tag_bundles = filter(copy(g:bundles), "has_key(v:val, 'tag')")
"let plain_bundles = filter(copy(g:bundles), "! has_key(v:val, 'tag') && ! has_key(v:val, 'commit') && ! has_key(v:val, 'branch')")
let plain_bundles = filter(copy(g:bundles), "! has_key(v:val, 'rev')")
let rev_bundles = filter(copy(g:bundles), "has_key(v:val, 'rev')")

"let branch_bundle_names = map(copy(branch_bundles), 'printf("%s, branch:%s", v:val.name_spec, v:val.branch )')
"let commit_bundle_names = map(copy(commit_bundles), 'printf("%s, commit:%s", v:val.name_spec, v:val.commit )')
"let tag_bundle_names = map(copy(tag_bundles) , 'printf("%s, tag:%s", v:val.name_spec, v:val.tag )')
let plain_bundle_names = map(copy(plain_bundles) , 'v:val.name_spec')
let rev_bundle_names = map(copy(rev_bundles) , 'printf("%s, %s", v:val.name_spec, v:val.rev )')

"return extend(extend(extend(plain_bundle_names, branch_bundle_names), commit_bundle_names), tag_bundle_names)
return extend(plain_bundle_names, rev_bundle_names)
endf

func! vundle#scripts#bundle_names(names)
return map(copy(a:names), ' printf("Bundle ' ."'%s'".'", v:val) ')
return map(copy(a:names), ' s:split_name(v:val) ')
endf

func! s:split_name(name)
let split_n = split(a:name, ', ')
if len(split_n) > 1
let ret_val = printf("Bundle '%s', '%s'", split_n[0], split_n[1])
else
let ret_val = printf("Bundle '%s'", split_n[0])
endif

return ret_val
endf

func! vundle#scripts#view(title, headers, results)
Expand Down