@@ -865,8 +865,8 @@ endfunction
865
865
866
866
function ! s: checkout (spec)
867
867
let sha = a: spec .commit
868
- let output = s: system (' git rev-parse HEAD' , a: spec .dir )
869
- if ! v: shell_error && ! s: hash_match (sha, s: lines (output)[0 ])
868
+ let [ output, shellerror] = s: system_with_error (' git rev-parse HEAD' , a: spec .dir )
869
+ if ! shellerror && ! s: hash_match (sha, s: lines (output)[0 ])
870
870
let output = s: system (
871
871
\ ' git fetch --depth 999999 && git checkout ' .s: esc (sha), a: spec .dir )
872
872
endif
@@ -1053,14 +1053,16 @@ function! s:update_finish()
1053
1053
if ! pos
1054
1054
continue
1055
1055
endif
1056
+ let shellerror = 0
1056
1057
if has_key (spec, ' commit' )
1057
1058
call s: log4 (name, ' Checking out ' .spec.commit)
1058
1059
let out = s: checkout (spec)
1059
1060
elseif has_key (spec, ' tag' )
1060
1061
let tag = spec.tag
1061
1062
if tag = ~ ' \*'
1062
- let tags = s: lines (s: system (' git tag --list ' .string (tag ).' --sort -version:refname 2>&1' , spec.dir ))
1063
- if ! v: shell_error && ! empty (tags )
1063
+ let [output, shellerror] = s: system_with_error (' git tag --list ' .string (tag ).' --sort -version:refname 2>&1' , spec.dir )
1064
+ let tags = s: lines (output)
1065
+ if ! shellerror && ! empty (tags )
1064
1066
let tag = tags [0 ]
1065
1067
call s: log4 (name, printf (' Latest tag for %s -> %s' , spec.tag , tag ))
1066
1068
call append (3 , ' ' )
@@ -1074,13 +1076,13 @@ function! s:update_finish()
1074
1076
let out = s: system (' git checkout -q ' .branch.' 2>&1'
1075
1077
\. (has_key (s: update .new , name) ? ' ' : (' && git merge --ff-only origin/' .branch.' 2>&1' )), spec.dir )
1076
1078
endif
1077
- if ! v: shell_error && filereadable (spec.dir .' /.gitmodules' ) &&
1079
+ if ! shellerror && filereadable (spec.dir .' /.gitmodules' ) &&
1078
1080
\ (s: update .force || has_key (s: update .new , name) || s: is_updated (spec.dir ))
1079
1081
call s: log4 (name, ' Updating submodules. This may take a while.' )
1080
1082
let out .= s: bang (' git submodule update --init --recursive 2>&1' , spec.dir )
1081
1083
endif
1082
- let msg = s: format_message (v: shell_error ? ' x' : ' -' , name, out)
1083
- if v: shell_error
1084
+ let msg = s: format_message (shellerror ? ' x' : ' -' , name, out)
1085
+ if shellerror
1084
1086
call add (s: update .errors, name)
1085
1087
call s: regress_bar ()
1086
1088
silent execute pos ' d _'
@@ -1203,8 +1205,9 @@ function! s:spawn(name, cmd, opts)
1203
1205
endif
1204
1206
else
1205
1207
let params = has_key (a: opts , ' dir' ) ? [a: cmd , a: opts .dir ] : [a: cmd ]
1206
- let job.lines = s: lines (call (' s:system' , params))
1207
- let job.error = v: shell_error != 0
1208
+ let [output, shellerror] = call (' s:system_with_error' , params)
1209
+ let job.lines = s: lines (output)
1210
+ let job.error = shellerror != 0
1208
1211
let job.running = 0
1209
1212
endif
1210
1213
endfunction
@@ -1997,26 +2000,52 @@ function! s:system(cmd, ...)
1997
2000
endtry
1998
2001
endfunction
1999
2002
2003
+ function ! s: system_with_error (cmd, ... )
2004
+ try
2005
+ let maxfuncdepth = &maxfuncdepth
2006
+ set maxfuncdepth = 99999
2007
+ let [sh , shrd] = s: chsh (1 )
2008
+ let cmd = a: 0 > 0 ? s: with_cd (a: cmd , a: 1 ) : a: cmd
2009
+ if s: vim8
2010
+ let [out, exit_code] = [' ' , 0 ]
2011
+ let job = job_start ([&shell , &shellcmdflag , cmd], {
2012
+ \ ' out_cb' : {ch ,msg- >[execute (" let out .= msg" ), out]},
2013
+ \ ' err_cb' : {ch ,msg- >[execute (" let out .= msg" ), out]},
2014
+ \ ' exit_cb' : {job,code- >[execute (" let exit_code=code" ), exit_code]},
2015
+ \ ' out_mode' : ' raw' })
2016
+ while job_status (job) == ' run'
2017
+ sleep 10 m
2018
+ endwhile
2019
+ return [out, exit_code]
2020
+ endif
2021
+ return [system (s: is_win ? ' (' .cmd.' )' : cmd), v: shell_error ]
2022
+ finally
2023
+ let [&shell , &shellredir , &maxfuncdepth ] = [sh , shrd, maxfuncdepth ]
2024
+ endtry
2025
+ endfunction
2026
+
2000
2027
function ! s: system_chomp (... )
2001
- let ret = call (' s:system ' , a: 000 )
2002
- return v: shell_error ? ' ' : substitute (ret , ' \n$' , ' ' , ' ' )
2028
+ let [ ret , shellerror] = call (' s:system_with_error ' , a: 000 )
2029
+ return shellerror ? ' ' : substitute (ret , ' \n$' , ' ' , ' ' )
2003
2030
endfunction
2004
2031
2005
2032
function ! s: git_validate (spec, check_branch)
2006
2033
let err = ' '
2007
2034
if isdirectory (a: spec .dir )
2008
- let result = s: lines (s: system (' git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url' , a: spec .dir ))
2035
+ let [output, shellerror] = s: system_with_error (' git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url' , a: spec .dir )
2036
+ let result = s: lines (output)
2009
2037
let remote = result[-1 ]
2010
- if v: shell_error
2038
+ if shellerror
2011
2039
let err = join ([remote, ' PlugClean required.' ], " \n " )
2012
2040
elseif ! s: compare_git_uri (remote, a: spec .uri)
2013
2041
let err = join ([' Invalid URI: ' .remote,
2014
2042
\ ' Expected: ' .a: spec .uri,
2015
2043
\ ' PlugClean required.' ], " \n " )
2016
2044
elseif a: check_branch && has_key (a: spec , ' commit' )
2017
- let result = s: lines (s: system (' git rev-parse HEAD 2>&1' , a: spec .dir ))
2045
+ let [output, shellerror] = s: system_with_error (' git rev-parse HEAD 2>&1' , a: spec .dir )
2046
+ let result = s: lines (output)
2018
2047
let sha = result[-1 ]
2019
- if v: shell_error
2048
+ if shellerror
2020
2049
let err = join (add (result, ' PlugClean required.' ), " \n " )
2021
2050
elseif ! s: hash_match (sha, a: spec .commit)
2022
2051
let err = join ([printf (' Invalid HEAD (expected: %s, actual: %s)' ,
@@ -2038,10 +2067,11 @@ function! s:git_validate(spec, check_branch)
2038
2067
\ branch, a: spec .branch)
2039
2068
endif
2040
2069
if empty (err)
2041
- let [ahead, behind ] = split ( s: lastline ( s: system (printf (
2070
+ let [output, shellerror ] = s: system_with_error (printf (
2042
2071
\ ' git rev-list --count --left-right HEAD...origin/%s' ,
2043
- \ a: spec .branch), a: spec .dir )), ' \t' )
2044
- if ! v: shell_error && ahead
2072
+ \ a: spec .branch), a: spec .dir )
2073
+ let [ahead, behind] = split (s: lastline (output), ' \t' )
2074
+ if ! shellerror && ahead
2045
2075
if behind
2046
2076
" Only mention PlugClean if diverged, otherwise it's likely to be
2047
2077
" pushable (and probably not that messed up).
@@ -2173,8 +2203,8 @@ function! s:upgrade()
2173
2203
let new = tmp . ' /plug.vim'
2174
2204
2175
2205
try
2176
- let out = s: system (printf (' git clone --depth 1 %s %s' , s: plug_src , tmp))
2177
- if v: shell_error
2206
+ let [ out, shellerror] = s: system_with_error (printf (' git clone --depth 1 %s %s' , s: plug_src , tmp))
2207
+ if shellerror
2178
2208
return s: err (' Error upgrading vim-plug: ' . out)
2179
2209
endif
2180
2210
0 commit comments