mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 12:33:46 -05:00
Thorough error reporting for broken system() calls
This commit is contained in:
@@ -95,6 +95,17 @@ function! s:git_command() abort
|
|||||||
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:System(cmd) abort
|
||||||
|
try
|
||||||
|
return system(a:cmd)
|
||||||
|
catch /^Vim\%((\a\+)\)\=:E484:/
|
||||||
|
let opts = ['shell', 'shellcmdflag', 'shellredir', 'shellquote', 'shellxquote', 'shellxescape', 'shellslash']
|
||||||
|
call filter(opts, 'exists("+".v:val) && !empty(eval("&".v:val))')
|
||||||
|
call map(opts, 'v:val."=".eval("&".v:val)')
|
||||||
|
call s:throw('failed to run `' . a:cmd . '` with ' . join(opts, ' '))
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Prepare(...) abort
|
function! fugitive#Prepare(...) abort
|
||||||
let args = copy(a:000)
|
let args = copy(a:000)
|
||||||
if empty(args)
|
if empty(args)
|
||||||
@@ -332,7 +343,7 @@ function! s:repo_git_command(...) dict abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_git_chomp(...) dict abort
|
function! s:repo_git_chomp(...) dict abort
|
||||||
return s:sub(system(call('fugitive#Prepare', [self.git_dir] + a:000)),'\n$','')
|
return s:sub(s:System(call('fugitive#Prepare', [self.git_dir] + a:000)),'\n$','')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_git_chomp_in_tree(...) dict abort
|
function! s:repo_git_chomp_in_tree(...) dict abort
|
||||||
@@ -2678,11 +2689,11 @@ function! s:TempCmd(out, cmd, ...) abort
|
|||||||
let redir = ' > ' . a:out
|
let redir = ' > ' . a:out
|
||||||
if s:winshell()
|
if s:winshell()
|
||||||
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
|
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
|
||||||
return system('cmd /c "' . prefix . s:gsub(cmd, '[<>]', cmd_escape_char . '&') . redir . '"')
|
return s:System('cmd /c "' . prefix . s:gsub(cmd, '[<>]', cmd_escape_char . '&') . redir . '"')
|
||||||
elseif &shell =~# 'fish'
|
elseif &shell =~# 'fish'
|
||||||
return system(' begin;' . prefix . cmd . redir . ';end ')
|
return s:System(' begin;' . prefix . cmd . redir . ';end ')
|
||||||
else
|
else
|
||||||
return system(' (' . prefix . cmd . redir . ') ')
|
return s:System(' (' . prefix . cmd . redir . ') ')
|
||||||
endif
|
endif
|
||||||
finally
|
finally
|
||||||
if exists('old_index')
|
if exists('old_index')
|
||||||
@@ -2705,7 +2716,7 @@ function! s:ReplaceCmd(cmd, ...) abort
|
|||||||
finally
|
finally
|
||||||
try
|
try
|
||||||
silent exe 'keepalt file '.s:fnameescape(fn)
|
silent exe 'keepalt file '.s:fnameescape(fn)
|
||||||
catch /^Vim\%((\a\+)\)\=:E302/
|
catch /^Vim\%((\a\+)\)\=:E302:/
|
||||||
endtry
|
endtry
|
||||||
call delete(tmp)
|
call delete(tmp)
|
||||||
if fnamemodify(bufname('$'), ':p') ==# tmp
|
if fnamemodify(bufname('$'), ':p') ==# tmp
|
||||||
@@ -2828,9 +2839,9 @@ function! fugitive#BufWriteCmd(...) abort
|
|||||||
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
|
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
|
||||||
call writefile([info],tmp)
|
call writefile([info],tmp)
|
||||||
if s:winshell()
|
if s:winshell()
|
||||||
let error = system('type '.s:gsub(tmp,'/','\\').'|'.fugitive#Prepare(dir, 'update-index', '--index-info'))
|
let error = s:System('type '.s:gsub(tmp,'/','\\').'|'.fugitive#Prepare(dir, 'update-index', '--index-info'))
|
||||||
else
|
else
|
||||||
let error = system(fugitive#Prepare(dir, 'update-index', '--index-info').' < '.tmp)
|
let error = s:System(fugitive#Prepare(dir, 'update-index', '--index-info').' < '.tmp)
|
||||||
endif
|
endif
|
||||||
if v:shell_error == 0
|
if v:shell_error == 0
|
||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
|
|||||||
Reference in New Issue
Block a user