mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Merge branch 'issue-84'
* issue-84: Now working with shellslash Fixed escaping Escape shell commands on windows.
This commit is contained in:
@@ -82,6 +82,18 @@ function! s:directory_of_file()
|
|||||||
return shellescape(fnamemodify(s:file(), ':h'))
|
return shellescape(fnamemodify(s:file(), ':h'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17
|
||||||
|
function! s:escape(str)
|
||||||
|
if &shellxquote ==# '"'
|
||||||
|
return '"' . substitute(a:str, '"', '""', 'g') . '"'
|
||||||
|
else
|
||||||
|
let esc = exists('+shellxescape') ? &shellxescape : '"&|<>()@^'
|
||||||
|
return &shellquote .
|
||||||
|
\ substitute(a:str, '['.esc.']', '&', 'g') .
|
||||||
|
\ get({'(': ')', '"(': ')"'}, &shellquote, &shellquote)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:discard_stdout_and_stderr()
|
function! s:discard_stdout_and_stderr()
|
||||||
if !exists('s:discard')
|
if !exists('s:discard')
|
||||||
if &shellredir ==? '>%s 2>&1'
|
if &shellredir ==? '>%s 2>&1'
|
||||||
@@ -94,17 +106,18 @@ function! s:discard_stdout_and_stderr()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:command_in_directory_of_file(cmd)
|
function! s:command_in_directory_of_file(cmd)
|
||||||
return 'cd ' . s:directory_of_file() . ' && ' . a:cmd
|
let s:cmd_in_dir = 'cd ' . s:directory_of_file() . ' && ' . a:cmd
|
||||||
|
return substitute(s:cmd_in_dir, "'", '"', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_in_a_git_repo()
|
function! s:is_in_a_git_repo()
|
||||||
let cmd = 'git rev-parse' . s:discard_stdout_and_stderr()
|
let cmd = s:escape('git rev-parse' . s:discard_stdout_and_stderr())
|
||||||
call system(s:command_in_directory_of_file(cmd))
|
call system(s:command_in_directory_of_file(cmd))
|
||||||
return !v:shell_error
|
return !v:shell_error
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_tracked_by_git()
|
function! s:is_tracked_by_git()
|
||||||
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:file())
|
let cmd = s:escape('git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:file()))
|
||||||
call system(s:command_in_directory_of_file(cmd))
|
call system(s:command_in_directory_of_file(cmd))
|
||||||
return !v:shell_error
|
return !v:shell_error
|
||||||
endfunction
|
endfunction
|
||||||
@@ -196,6 +209,7 @@ function! s:run_diff()
|
|||||||
if s:grep_available
|
if s:grep_available
|
||||||
let cmd .= s:grep_command
|
let cmd .= s:grep_command
|
||||||
endif
|
endif
|
||||||
|
let cmd = s:escape(cmd)
|
||||||
let diff = system(s:command_in_directory_of_file(cmd))
|
let diff = system(s:command_in_directory_of_file(cmd))
|
||||||
return diff
|
return diff
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user