Skip to content

Commit 93b7025

Browse files
authored
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
1 parent 68fef9c commit 93b7025

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

plug.vim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ if s:is_win
369369
function! s:batchfile(cmd)
370370
let batchfile = tempname().'.bat'
371371
call writefile(s:wrap_cmds(a:cmd), batchfile)
372-
let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 1})
373-
if &shell =~# 'powershell\.exe$'
372+
let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 0})
373+
if &shell =~# 'powershell\.exe'
374374
let cmd = '& ' . cmd
375375
endif
376376
return [batchfile, cmd]
@@ -915,7 +915,7 @@ function! s:checkout(spec)
915915
let output = s:system('git rev-parse HEAD', a:spec.dir)
916916
if !v:shell_error && !s:hash_match(sha, s:lines(output)[0])
917917
let output = s:system(
918-
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha).' --', a:spec.dir)
918+
\ 'git fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
919919
endif
920920
return output
921921
endfunction
@@ -1120,12 +1120,12 @@ function! s:update_finish()
11201120
endif
11211121
endif
11221122
call s:log4(name, 'Checking out '.tag)
1123-
let out = s:system('git checkout -q '.s:esc(tag).' -- 2>&1', spec.dir)
1123+
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
11241124
else
1125-
let branch = s:esc(get(spec, 'branch', 'master'))
1126-
call s:log4(name, 'Merging origin/'.branch)
1127-
let out = s:system('git checkout -q '.branch.' -- 2>&1'
1128-
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir)
1125+
let branch = get(spec, 'branch', 'master')
1126+
call s:log4(name, 'Merging origin/'.s:esc(branch))
1127+
let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1'
1128+
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir)
11291129
endif
11301130
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
11311131
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
@@ -1169,7 +1169,7 @@ function! s:job_abort()
11691169
silent! call job_stop(j.jobid)
11701170
endif
11711171
if j.new
1172-
call s:system('rm -rf ' . plug#shellescape(g:plugs[name].dir))
1172+
call s:rm_rf(g:plugs[name].dir)
11731173
endif
11741174
endfor
11751175
let s:jobs = {}
@@ -2005,9 +2005,9 @@ function! plug#shellescape(arg, ...)
20052005
let opts = a:0 > 0 && type(a:1) == s:TYPE.dict ? a:1 : {}
20062006
let shell = get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh')
20072007
let script = get(opts, 'script', 1)
2008-
if shell =~# 'cmd\.exe$'
2008+
if shell =~# 'cmd\.exe'
20092009
return s:shellesc_cmd(a:arg, script)
2010-
elseif shell =~# 'powershell\.exe$' || shell =~# 'pwsh$'
2010+
elseif shell =~# 'powershell\.exe' || shell =~# 'pwsh$'
20112011
return s:shellesc_ps1(a:arg)
20122012
endif
20132013
return shellescape(a:arg)
@@ -2485,7 +2485,7 @@ function! s:revert()
24852485
return
24862486
endif
24872487

2488-
call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch).' --', g:plugs[name].dir)
2488+
call s:system('git reset --hard HEAD@{1} && git checkout '.plug#shellescape(g:plugs[name].branch).' --', g:plugs[name].dir)
24892489
setlocal modifiable
24902490
normal! "_dap
24912491
setlocal nomodifiable

0 commit comments

Comments
 (0)