343343" return -- the URL for the origin remote (string)
344344" ---------------------------------------------------------------------------
345345func ! s: get_current_origin_url (bundle) abort
346- let cmd = ' cd ' .vundle#installer#shellesc (a: bundle .path ()).' && git config --get remote.origin.url'
347- let cmd = vundle#installer#shellesc_cd (cmd)
346+ let cmd = s: make_git_command (a: bundle , [' config' , ' --get' , ' remote.origin.url' ])
348347 let out = s: strip (s: system (cmd))
349348 return out
350349endf
@@ -357,12 +356,37 @@ endf
357356" return -- A 15 character log sha for the current HEAD
358357" ---------------------------------------------------------------------------
359358func ! s: get_current_sha (bundle)
360- let cmd = ' cd ' .vundle#installer#shellesc (a: bundle .path ()).' && git rev-parse HEAD'
361- let cmd = vundle#installer#shellesc_cd (cmd)
359+ let cmd = s: make_sync_command (a: bundle , [' rev-parse' , ' HEAD' ])
362360 let out = s: system (cmd)[0 :15 ]
363361 return out
364362endf
365363
364+ " ---------------------------------------------------------------------------
365+ " Build a safe (escaped) git command
366+ "
367+ " bundle -- A bundle object to get the path to the git dir
368+ " args -- A list of arguments to the git executable
369+ " return -- A string containing the escaped shell command
370+ " ---------------------------------------------------------------------------
371+ func ! s: make_git_command (bundle, args ) abort
372+ let workdir = a: bundle .path ()
373+ let gitdir = workdir.' /.git/'
374+
375+ let git = [' git' , ' --git-dir=' .gitdir, ' --work-tree=' .workdir]
376+
377+ return join (map (copy (git + args ), ' vundle#installer#shellesc' ))
378+ endf
379+
380+ " ---------------------------------------------------------------------------
381+ " Build a safe (escaped) command from list of git args
382+ "
383+ " bundle -- A bundle object to get the path to the git dir
384+ " argss -- A list of lists of arguments to successive git calls
385+ " return -- A string containing the escaped shell command
386+ " ---------------------------------------------------------------------------
387+ func ! s: make_git_commands (bundle, argss) abort
388+ return join (map (a: argss , ' s:make_git_command(s:bundle, {})' ), ' && ' )
389+ endf
366390
367391" ---------------------------------------------------------------------------
368392" Create the appropriate sync command to run according to the current state of
@@ -388,14 +412,12 @@ func! s:make_sync_command(bang, bundle) abort
388412 call s: log (' > Plugin ' . a: bundle .name . ' new URI: ' . a: bundle .uri)
389413 " Directory names match but the origin remotes are not the same
390414 let cmd_parts = [
391- \ ' cd ' .vundle#installer#shellesc (a: bundle .path ()) ,
392- \ ' git remote set-url origin ' . vundle#installer#shellesc (a: bundle .uri),
393- \ ' git fetch' ,
394- \ ' git reset --hard origin/HEAD' ,
395- \ ' git submodule update --init --recursive' ,
396- \ ]
397- let cmd = join (cmd_parts, ' && ' )
398- let cmd = vundle#installer#shellesc_cd (cmd)
415+ [ ' remote' , ' set-url' , ' origin' , a: bundle .uri ],
416+ [ ' fetch' ],
417+ [ ' reset' , ' --hard' , ' origin/HEAD' ],
418+ [ ' submodule' , ' update' , ' --init' , ' --recursive' ],
419+ ]
420+ let cmd = s: make_git_commands (a: bundle , cmd_parts)
399421 let initial_sha = ' '
400422 return [cmd, initial_sha]
401423 endif
0 commit comments