mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 03:53:47 -05:00
Avoid potential shell (un)quoting problems in NeoVim.
See neovim/neovim#4746 for a discussion.
This commit is contained in:
@@ -17,7 +17,15 @@ function! gitgutter#async#execute(cmd) abort
|
|||||||
let bufnr = gitgutter#utility#bufnr()
|
let bufnr = gitgutter#utility#bufnr()
|
||||||
|
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
let job_id = jobstart([&shell, &shellcmdflag, a:cmd], {
|
if has('unix')
|
||||||
|
let command = ["/bin/bash", "-c", a:cmd]
|
||||||
|
elseif has('win32')
|
||||||
|
let command = ["cmd.exe", "/c", a:cmd]
|
||||||
|
else
|
||||||
|
throw 'unknown os'
|
||||||
|
endif
|
||||||
|
" Make the job use a shell while avoiding (un)quoting problems.
|
||||||
|
let job_id = jobstart(command, {
|
||||||
\ 'buffer': bufnr,
|
\ 'buffer': bufnr,
|
||||||
\ 'on_stdout': function('gitgutter#async#handle_diff_job_nvim'),
|
\ 'on_stdout': function('gitgutter#async#handle_diff_job_nvim'),
|
||||||
\ 'on_stderr': function('gitgutter#async#handle_diff_job_nvim'),
|
\ 'on_stderr': function('gitgutter#async#handle_diff_job_nvim'),
|
||||||
@@ -34,10 +42,25 @@ function! gitgutter#async#execute(cmd) abort
|
|||||||
call s:job_started(job_id)
|
call s:job_started(job_id)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
" Make the job use a shell.
|
||||||
|
"
|
||||||
" Pass a handler for stdout but not for stderr so that errors are
|
" Pass a handler for stdout but not for stderr so that errors are
|
||||||
" ignored (and thus signs are not updated; this assumes that an error
|
" ignored (and thus signs are not updated; this assumes that an error
|
||||||
" only occurs when a file is not tracked by git).
|
" only occurs when a file is not tracked by git).
|
||||||
let job = job_start([&shell, &shellcmdflag, a:cmd], {
|
|
||||||
|
if has('unix')
|
||||||
|
let command = ["/bin/bash", "-c", a:cmd]
|
||||||
|
elseif has('win32')
|
||||||
|
" Help docs recommend {command} be a string on Windows. But I think
|
||||||
|
" they also say that will run the command directly, which I believe would
|
||||||
|
" mean the redirection and pipe stuff wouldn't work.
|
||||||
|
" let command = "cmd.exe /c ".a:cmd
|
||||||
|
let command = ["cmd.exe", "/c", a:cmd]
|
||||||
|
else
|
||||||
|
throw 'unknown os'
|
||||||
|
endif
|
||||||
|
|
||||||
|
let job = job_start(command, {
|
||||||
\ 'out_cb': 'gitgutter#async#handle_diff_job_vim',
|
\ 'out_cb': 'gitgutter#async#handle_diff_job_vim',
|
||||||
\ 'close_cb': 'gitgutter#async#handle_diff_job_vim_close'
|
\ 'close_cb': 'gitgutter#async#handle_diff_job_vim_close'
|
||||||
\ })
|
\ })
|
||||||
|
|||||||
Reference in New Issue
Block a user