Skip to content

Instantly share code, notes, and snippets.

@StanAngeloff
Created April 20, 2012 09:25
Show Gist options
  • Save StanAngeloff/2427319 to your computer and use it in GitHub Desktop.
Save StanAngeloff/2427319 to your computer and use it in GitHub Desktop.
--- a/installer.vim 2012-04-20 12:23:31.062007345 +0300
+++ b/installer.vim 2012-04-20 12:23:26.338007445 +0300
@@ -201,50 +201,65 @@
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
- endif
- else
- let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path())
+ 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('')
- call s:log('Bundle '.a:bundle.name_spec)
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'
+ 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 s:add_to_updated_bundles(out, a:bundle)
+ 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())
+
+ let out = s:system(cmd)
+ call s:log('$ '.cmd)
+ call s:log('> '.out)
+
+ if 0 != v:shell_error | return 'error' | endif
+
+ return 'new'
+ endif
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment