commit 66a921bbe38bea19f6b581c8a56d5a8a41209e35 (tree)
parent 23570688d2a56ca50551a486bf57078fea21ab1f
Author: Tim Pope <code@tpope.net>
Date: Thu, 28 Jul 2022 08:46:14 -0400
Consistently handle missing command jobs across platforms
* On UNIX, jobs proceed normally, and exit with status 122.
* On Windows, jobs fail early, and no callbacks run.
* On Neovim, an exception is thrown.
Normalize the second and third cases to behave like the first, as that
was my assumed behavior during the initial implementation.
References: https://github.com/tpope/vim-fugitive/issues/1815
Diffstat:
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -387,11 +387,15 @@ function! s:JobExecute(argv, jopts, stdin, callback, ...) abort
\ 'stdout_buffered': v:true,
\ 'stderr_buffered': v:true,
\ 'on_exit': function('s:JobNvimExit', [dict, cb])})
- let dict.job = jobstart(a:argv, a:jopts)
- if !empty(a:stdin)
- call chansend(dict.job, a:stdin)
- call chanclose(dict.job, 'stdin')
- endif
+ try
+ let dict.job = jobstart(a:argv, a:jopts)
+ if !empty(a:stdin)
+ call chansend(dict.job, a:stdin)
+ call chanclose(dict.job, 'stdin')
+ endif
+ catch /^Vim\%((\a\+)\)\=:E475:/
+ let [dict.exit_status, dict.stdout, dict.stderr] = [122, [''], ['']]
+ endtry
elseif exists('*ch_close_in')
let temp = tempname()
call extend(a:jopts, {
@@ -408,6 +412,10 @@ function! s:JobExecute(argv, jopts, stdin, callback, ...) abort
call writefile(a:stdin, a:jopts.in_name, 'b')
endif
let dict.job = job_start(a:argv, a:jopts)
+ if job_status(dict.job) ==# 'fail'
+ let [dict.exit_status, dict.stdout, dict.stderr] = [122, [''], ['']]
+ unlet dict.job
+ endif
elseif &shell !~# 'sh' || &shell =~# 'fish\|\%(powershell\|pwsh\)\%(\.exe\)\=$'
throw 'fugitive: Vim 8 or higher required to use ' . &shell
else