mv restore into gitgutter#utility#system

This commit is contained in:
Nikita Kouevda
2023-08-31 07:50:14 -07:00
parent a5e0740801
commit 28d463f199
4 changed files with 17 additions and 18 deletions

View File

@@ -6,8 +6,8 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+. " True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version') let [_, error_code] = gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error return !error_code
endfunction endfunction
let s:c_flag = s:git_supports_command_line_config_override() let s:c_flag = s:git_supports_command_line_config_override()
@@ -89,8 +89,8 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1) let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = gitgutter#git().' --no-pager show '.index_name let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd) let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd) let [_, error_code] = gitgutter#utility#system(cmd)
if v:shell_error if error_code
throw 'gitgutter file unknown in base' throw 'gitgutter file unknown in base'
endif endif
endif endif
@@ -176,9 +176,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
return 'async' return 'async'
else else
let diff = gitgutter#utility#system(cmd) let [diff, error_code] = gitgutter#utility#system(cmd)
if v:shell_error if error_code
call gitgutter#debug#log(diff) call gitgutter#debug#log(diff)
throw 'gitgutter diff failed' throw 'gitgutter diff failed'
endif endif

View File

@@ -309,7 +309,7 @@ function! s:stage(hunk_diff)
let cmd = gitgutter#utility#cd_cmd(bufnr, let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' add '. \ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr))) \ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd) let [_, error_code] = gitgutter#utility#system(cmd)
else else
return return
endif endif
@@ -317,12 +317,12 @@ function! s:stage(hunk_diff)
else else
let diff = s:adjust_header(bufnr, a:hunk_diff) let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index. " Apply patch to index.
call gitgutter#utility#system( let [_, error_code] = gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '), \ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff) \ diff)
endif endif
if v:shell_error if error_code
call gitgutter#utility#warn('Patch does not apply') call gitgutter#utility#warn('Patch does not apply')
else else
if exists('#User#GitGutterStage') if exists('#User#GitGutterStage')

View File

@@ -93,10 +93,13 @@ function! gitgutter#utility#system(cmd, ...) abort
call gitgutter#debug#log(a:cmd, a:000) call gitgutter#debug#log(a:cmd, a:000)
call s:use_known_shell() call s:use_known_shell()
let prev_error_code = v:shell_error
silent let output = (a:0 == 0) ? system(a:cmd) : system(a:cmd, a:1) silent let output = (a:0 == 0) ? system(a:cmd) : system(a:cmd, a:1)
let error_code = v:shell_error
silent call system('exit ' . prev_error_code)
call s:restore_shell() call s:restore_shell()
return output return [output, error_code]
endfunction endfunction
function! gitgutter#utility#has_repo_path(bufnr) function! gitgutter#utility#has_repo_path(bufnr)
@@ -161,9 +164,9 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
return 'async' return 'async'
endif endif
let listing = gitgutter#utility#system(cmd) let [listing, error_code] = gitgutter#utility#system(cmd)
if v:shell_error if error_code
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2) call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
return return
endif endif
@@ -184,7 +187,7 @@ function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let cmd = gitgutter#utility#cd_cmd(a:bufnr, let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ gitgutter#git().' check-attr filter -- '. \ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr))) \ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd) let [out, _] = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified' let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered) call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif endif

View File

@@ -320,11 +320,7 @@ augroup gitgutter
" vim -o file1 file2 " vim -o file1 file2
autocmd VimEnter * if winnr() != winnr('$') | call gitgutter#all(0) | endif autocmd VimEnter * if winnr() != winnr('$') | call gitgutter#all(0) | endif
autocmd ShellCmdPost * autocmd ShellCmdPost * call gitgutter#all(1)
\ let s:prev_shell_error = v:shell_error |
\ call gitgutter#all(1) |
\ silent! execute '!exit ' .. s:prev_shell_error |
\ redraw!
autocmd BufLeave term://* call gitgutter#all(1) autocmd BufLeave term://* call gitgutter#all(1)
autocmd User FugitiveChanged call gitgutter#all(1) autocmd User FugitiveChanged call gitgutter#all(1)