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 ()).' && ' .
347- g: vundle #git_executable.' config --get remote.origin.url'
348- let cmd = vundle#installer#shellesc_cd (cmd)
346+ let cmd = s: make_git_command (a: bundle , [' config' , ' --get' , ' remote.origin.url' ])
349347 let out = s: strip (s: system (cmd))
350348 return out
351349endf
@@ -358,13 +356,37 @@ endf
358356" return -- A 15 character log sha for the current HEAD
359357" ---------------------------------------------------------------------------
360358func ! s: get_current_sha (bundle)
361- let cmd = ' cd ' .vundle#installer#shellesc (a: bundle .path ()).' && ' .
362- g: vundle #git_executable.' rev-parse HEAD'
363- let cmd = vundle#installer#shellesc_cd (cmd)
359+ let cmd = s: make_git_command (a: bundle , [' rev-parse' , ' HEAD' ])
364360 let out = s: system (cmd)[0 :15 ]
365361 return out
366362endf
367363
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 = [g: vundle #git_executable, ' --git-dir=' .gitdir, ' --work-tree=' .workdir]
376+
377+ return join (map (git + a: args , ' vundle#installer#shellesc(v:val)' ))
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(a:bundle, v:val)' ), ' && ' )
389+ endf
368390
369391" ---------------------------------------------------------------------------
370392" Create the appropriate sync command to run according to the current state of
@@ -390,14 +412,12 @@ func! s:make_sync_command(bang, bundle) abort
390412 call s: log (' > Plugin ' . a: bundle .name . ' new URI: ' . a: bundle .uri)
391413 " Directory names match but the origin remotes are not the same
392414 let cmd_parts = [
393- \ ' cd ' .vundle#installer#shellesc (a: bundle .path ()) ,
394- \ g: vundle #git_executable.' remote set-url origin ' . vundle#installer#shellesc (a: bundle .uri),
395- \ g: vundle #git_executable.' fetch' ,
396- \ g: vundle #git_executable.' reset --hard origin/HEAD' ,
397- \ g: vundle #git_executable.' submodule update --init --recursive' ,
398- \ ]
399- let cmd = join (cmd_parts, ' && ' )
400- 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)
401421 let initial_sha = ' '
402422 return [cmd, initial_sha]
403423 endif
0 commit comments