Browse Source

Don't rely on `git` command output.

This commit introduces `rev-parse HEAD` in order to parse the commits at
which HEAD points before and after `git pull`. If the commits are the
same, the bundle is considered 'up-to-date'. If the commits are different,
then the HEAD was fast-forwarded and the bundle is considered 'updated'.

This approach is more reliable than parsing the output of the `git` command
as it can differ between OSes and locales.

Tested on Ubuntu 11.10. The control characters at the end of the output of
`git rev-parse` are stripped away using '[:cntrl:]', assuming cross-platform.
pull/165/head
Stan Angeloff 14 years ago
parent
commit
fa4efe8d69
1 changed files with 40 additions and 25 deletions
  1. +40
    -25
      autoload/vundle/installer.vim

+ 40
- 25
autoload/vundle/installer.vim View File

@ -201,50 +201,65 @@ func! s:helptags(rtp) abort
endf
func! s:sync(bang, bundle) abort
call s:log('')
call s:log('Bundle '.a:bundle.name_spec)
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'
let change_cmd = 'cd '.shellescape(a:bundle.path())
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 change_cmd = substitute(change_cmd, '^cd ','cd /d ','') " add /d switch to change drives
let change_cmd = '"'.change_cmd.'"' " enclose in quotes
endif
let cmd = change_cmd.' && git rev-parse HEAD'
let initial_sha = s:system(cmd)
if 0 != v:shell_error | return 'error' | endif
let cmd = change_cmd.' && git pull'
let out = s:system(cmd)
call s:log('$ '.cmd)
call s:log('> '.out)
if 0 != v:shell_error | return 'error' | endif
let cmd = change_cmd.' && git rev-parse HEAD'
let updated_sha = s:system(cmd)
if 0 != v:shell_error | return 'error' | endif
let initial_sha = s:strip_right(initial_sha)
let updated_sha = s:strip_right(updated_sha)
if initial_sha == updated_sha
return 'todate'
endif
call add(g:updated_bundles, [initial_sha, updated_sha, a:bundle])
return 'updated'
else
let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path())
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)
let out = s:system(cmd)
call s:log('$ '.cmd)
call s:log('> '.out)
if 0 != v:shell_error
return 'error'
end
if 0 != v:shell_error | return 'error' | endif
if out =~# 'Cloning into '
return 'new'
elseif out =~# 'up-to-date'
return 'todate'
endif
call s:add_to_updated_bundles(out, a:bundle)
return 'updated'
endf
func! s:system(cmd) abort
return system(a:cmd)
endf
func! s:add_to_updated_bundles(out, bundle) abort
let git_pull_shas = matchlist(a:out, 'Updating \(\w\+\)..\(\w\+\)')
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:strip_right(input)
return substitute(a:input, '[[:space:][:cntrl:]]\+$', '', '')
endfunction
func! s:log(str) abort
let fmt = '%y%m%d %H:%M:%S'


Loading…
Cancel
Save