Return bundle status without using git output text

Instead checking for specific text in the output of the git commands, determine
the status of the bundle by comparing the sha of HEAD before and after the
git pull command.
This commit is contained in:
Matt Furden 2012-04-20 12:40:16 -07:00
parent d62b51a8fe
commit e56d772ecf

View File

@ -212,8 +212,12 @@ func! s:sync(bang, bundle) abort
let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives
let cmd = '"'.cmd.'"' " enclose in quotes let cmd = '"'.cmd.'"' " enclose in quotes
endif endif
let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD'
let initial_sha = s:system(get_current_sha)[0:15]
else else
let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path())
let initial_sha = ''
endif endif
let out = s:system(cmd) let out = s:system(cmd)
@ -226,13 +230,17 @@ func! s:sync(bang, bundle) abort
return 'error' return 'error'
end end
if out =~# 'Cloning into ' if empty(initial_sha)
return 'new' return 'new'
elseif out =~# 'up-to-date' endif
let updated_sha = s:system(get_current_sha)[0:15]
if initial_sha == updated_sha
return 'todate' return 'todate'
endif endif
call s:add_to_updated_bundles(out, a:bundle) call add(g:updated_bundles, [initial_sha, updated_sha, a:bundle])
return 'updated' return 'updated'
endf endf
@ -240,17 +248,6 @@ func! s:system(cmd) abort
return system(a:cmd) return system(a:cmd)
endf endf
func! s:add_to_updated_bundles(out, bundle) abort
let git_pull_shas = matchlist(a:out, 'Updating \(\w\+\)..\(\w\+\)')
if (empty(git_pull_shas)) | return | endif
let initial_sha = git_pull_shas[1]
let updated_sha = git_pull_shas[2]
call add(g:updated_bundles, [initial_sha, updated_sha, a:bundle])
endfunc
func! s:log(str) abort func! s:log(str) abort
let fmt = '%y%m%d %H:%M:%S' let fmt = '%y%m%d %H:%M:%S'
call add(g:vundle_log, '['.strftime(fmt).'] '.a:str) call add(g:vundle_log, '['.strftime(fmt).'] '.a:str)