Fix shellescaping for git refs and batchfile on Windows (#909)

It was using s:esc() which escapes spaces with a backslash.
This does not work on Windows.

&shell could be escaped on because of spaces.
See patch-8.0.1455 and related 8.1.x patches that address this
for $SHELL on Unix and git-bash on Windows.

Related #852, #908 
Close #890
This commit is contained in:
Jan Edmund Lazo 2019-12-01 21:01:17 -05:00 committed by GitHub
parent 68fef9c2fd
commit 93b702512d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -369,8 +369,8 @@ if s:is_win
function! s:batchfile(cmd) function! s:batchfile(cmd)
let batchfile = tempname().'.bat' let batchfile = tempname().'.bat'
call writefile(s:wrap_cmds(a:cmd), batchfile) call writefile(s:wrap_cmds(a:cmd), batchfile)
let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 1}) let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 0})
if &shell =~# 'powershell\.exe$' if &shell =~# 'powershell\.exe'
let cmd = '& ' . cmd let cmd = '& ' . cmd
endif endif
return [batchfile, cmd] return [batchfile, cmd]
@ -915,7 +915,7 @@ function! s:checkout(spec)
let output = s:system('git rev-parse HEAD', a:spec.dir) let output = s:system('git rev-parse HEAD', a:spec.dir)
if !v:shell_error && !s:hash_match(sha, s:lines(output)[0]) if !v:shell_error && !s:hash_match(sha, s:lines(output)[0])
let output = s:system( let output = s:system(
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha).' --', a:spec.dir) \ 'git fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
endif endif
return output return output
endfunction endfunction
@ -1120,12 +1120,12 @@ function! s:update_finish()
endif endif
endif endif
call s:log4(name, 'Checking out '.tag) call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.s:esc(tag).' -- 2>&1', spec.dir) let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
else else
let branch = s:esc(get(spec, 'branch', 'master')) let branch = get(spec, 'branch', 'master')
call s:log4(name, 'Merging origin/'.branch) call s:log4(name, 'Merging origin/'.s:esc(branch))
let out = s:system('git checkout -q '.branch.' -- 2>&1' let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1'
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir) \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir)
endif endif
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir)) \ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
@ -1169,7 +1169,7 @@ function! s:job_abort()
silent! call job_stop(j.jobid) silent! call job_stop(j.jobid)
endif endif
if j.new if j.new
call s:system('rm -rf ' . plug#shellescape(g:plugs[name].dir)) call s:rm_rf(g:plugs[name].dir)
endif endif
endfor endfor
let s:jobs = {} let s:jobs = {}
@ -2005,9 +2005,9 @@ function! plug#shellescape(arg, ...)
let opts = a:0 > 0 && type(a:1) == s:TYPE.dict ? a:1 : {} let opts = a:0 > 0 && type(a:1) == s:TYPE.dict ? a:1 : {}
let shell = get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh') let shell = get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh')
let script = get(opts, 'script', 1) let script = get(opts, 'script', 1)
if shell =~# 'cmd\.exe$' if shell =~# 'cmd\.exe'
return s:shellesc_cmd(a:arg, script) return s:shellesc_cmd(a:arg, script)
elseif shell =~# 'powershell\.exe$' || shell =~# 'pwsh$' elseif shell =~# 'powershell\.exe' || shell =~# 'pwsh$'
return s:shellesc_ps1(a:arg) return s:shellesc_ps1(a:arg)
endif endif
return shellescape(a:arg) return shellescape(a:arg)
@ -2485,7 +2485,7 @@ function! s:revert()
return return
endif endif
call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch).' --', g:plugs[name].dir) call s:system('git reset --hard HEAD@{1} && git checkout '.plug#shellescape(g:plugs[name].branch).' --', g:plugs[name].dir)
setlocal modifiable setlocal modifiable
normal! "_dap normal! "_dap
setlocal nomodifiable setlocal nomodifiable