mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 12:53:52 -05:00
Add stdin support to FugitiveExecute()
This commit is contained in:
@@ -282,6 +282,7 @@ function! s:JobVimExit(dict, callback, temp, job, status) abort
|
|||||||
call delete(a:temp . '.err')
|
call delete(a:temp . '.err')
|
||||||
let a:dict.stdout = readfile(a:temp . '.out', 'b')
|
let a:dict.stdout = readfile(a:temp . '.out', 'b')
|
||||||
call delete(a:temp . '.out')
|
call delete(a:temp . '.out')
|
||||||
|
call delete(a:temp . '.in')
|
||||||
call remove(a:dict, 'job')
|
call remove(a:dict, 'job')
|
||||||
call call(a:callback[0], [a:dict] + a:callback[1:-1])
|
call call(a:callback[0], [a:dict] + a:callback[1:-1])
|
||||||
endfunction
|
endfunction
|
||||||
@@ -293,7 +294,7 @@ function! s:JobNvimExit(dict, callback, job, data, type) dict abort
|
|||||||
call call(a:callback[0], [a:dict] + a:callback[1:-1])
|
call call(a:callback[0], [a:dict] + a:callback[1:-1])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:JobExecute(argv, jopts, callback, ...) abort
|
function! s:JobExecute(argv, jopts, stdin, callback, ...) abort
|
||||||
let dict = a:0 ? a:1 : {}
|
let dict = a:0 ? a:1 : {}
|
||||||
let cb = len(a:callback) ? a:callback : [function('len')]
|
let cb = len(a:callback) ? a:callback : [function('len')]
|
||||||
if exists('*jobstart')
|
if exists('*jobstart')
|
||||||
@@ -302,6 +303,10 @@ function! s:JobExecute(argv, jopts, callback, ...) abort
|
|||||||
\ 'stderr_buffered': v:true,
|
\ 'stderr_buffered': v:true,
|
||||||
\ 'on_exit': function('s:JobNvimExit', [dict, cb])})
|
\ 'on_exit': function('s:JobNvimExit', [dict, cb])})
|
||||||
let dict.job = jobstart(a:argv, a:jopts)
|
let dict.job = jobstart(a:argv, a:jopts)
|
||||||
|
if !empty(a:stdin)
|
||||||
|
call chansend(dict.job, a:stdin)
|
||||||
|
call chanclose(dict.job, 'stdin')
|
||||||
|
endif
|
||||||
elseif exists('*job_start')
|
elseif exists('*job_start')
|
||||||
let temp = tempname()
|
let temp = tempname()
|
||||||
call extend(a:jopts, {
|
call extend(a:jopts, {
|
||||||
@@ -310,6 +315,13 @@ function! s:JobExecute(argv, jopts, callback, ...) abort
|
|||||||
\ 'err_io': 'file',
|
\ 'err_io': 'file',
|
||||||
\ 'err_name': temp . '.err',
|
\ 'err_name': temp . '.err',
|
||||||
\ 'exit_cb': function('s:JobVimExit', [dict, cb, temp])})
|
\ 'exit_cb': function('s:JobVimExit', [dict, cb, temp])})
|
||||||
|
if a:stdin ==# ['']
|
||||||
|
let a:jopts.in_io = 'null'
|
||||||
|
elseif !empty(a:stdin)
|
||||||
|
let a:jopts.in_io = 'file'
|
||||||
|
let a:jopts.in_name = temp . '.in'
|
||||||
|
call writefile(a:stdin, a:jopts.in_name, 'b')
|
||||||
|
endif
|
||||||
let dict.job = job_start(a:argv, a:jopts)
|
let dict.job = job_start(a:argv, a:jopts)
|
||||||
elseif &shell !~# 'sh' || &shell =~# 'fish\|\%(powershell\|pwsh\)\%(\.exe\)\=$'
|
elseif &shell !~# 'sh' || &shell =~# 'fish\|\%(powershell\|pwsh\)\%(\.exe\)\=$'
|
||||||
throw 'fugitive: Vim 8 or higher required to use ' . &shell
|
throw 'fugitive: Vim 8 or higher required to use ' . &shell
|
||||||
@@ -317,7 +329,7 @@ function! s:JobExecute(argv, jopts, callback, ...) abort
|
|||||||
let cmd = s:shellesc(a:argv)
|
let cmd = s:shellesc(a:argv)
|
||||||
let outfile = tempname()
|
let outfile = tempname()
|
||||||
try
|
try
|
||||||
let dict.stderr = split(system(' (' . cmd . ' >' . outfile . ') '), "\n", 1)
|
let dict.stderr = split(system(' (' . cmd . ' >' . outfile . ') ', join(a:stdin, "\n")), "\n", 1)
|
||||||
let dict.exit_status = v:shell_error
|
let dict.exit_status = v:shell_error
|
||||||
let dict.stdout = readfile(outfile, 'b')
|
let dict.stdout = readfile(outfile, 'b')
|
||||||
call call(cb[0], [dict] + cb[1:-1])
|
call call(cb[0], [dict] + cb[1:-1])
|
||||||
@@ -422,7 +434,7 @@ let s:git_versions = {}
|
|||||||
function! fugitive#GitVersion(...) abort
|
function! fugitive#GitVersion(...) abort
|
||||||
let git = s:GitShellCmd()
|
let git = s:GitShellCmd()
|
||||||
if !has_key(s:git_versions, git)
|
if !has_key(s:git_versions, git)
|
||||||
let s:git_versions[git] = matchstr(get(s:JobExecute(s:GitCmd() + ['--version'], {}, [], {}).stdout, 0, ''), '\d[^[:space:]]\+')
|
let s:git_versions[git] = matchstr(get(s:JobExecute(s:GitCmd() + ['--version'], {}, [], [], {}).stdout, 0, ''), '\d[^[:space:]]\+')
|
||||||
endif
|
endif
|
||||||
if !a:0
|
if !a:0
|
||||||
return s:git_versions[git]
|
return s:git_versions[git]
|
||||||
@@ -700,11 +712,23 @@ endfunction
|
|||||||
function! fugitive#Execute(...) abort
|
function! fugitive#Execute(...) abort
|
||||||
let cb = copy(a:000)
|
let cb = copy(a:000)
|
||||||
let cmd = []
|
let cmd = []
|
||||||
|
let stdin = []
|
||||||
while len(cb) && type(cb[0]) !=# type(function('tr'))
|
while len(cb) && type(cb[0]) !=# type(function('tr'))
|
||||||
|
if type(cb[0]) ==# type({}) && has_key(cb[0], 'stdin')
|
||||||
|
if type(cb[0].stdin) == type([])
|
||||||
|
call extend(stdin, cb[0].stdin)
|
||||||
|
elseif type(cb[0].stdin) == type('')
|
||||||
|
call extend(stdin, readfile(cb[0].stdin, 'b'))
|
||||||
|
endif
|
||||||
|
if len(keys(cb[0])) == 1
|
||||||
|
call remove(cb, 0)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
endif
|
||||||
call add(cmd, remove(cb, 0))
|
call add(cmd, remove(cb, 0))
|
||||||
endwhile
|
endwhile
|
||||||
let [argv, jopts, dict] = call('fugitive#PrepareJob', cmd)
|
let [argv, jopts, dict] = call('fugitive#PrepareJob', cmd)
|
||||||
return s:JobExecute(argv, jopts, cb, dict)
|
return s:JobExecute(argv, jopts, stdin, cb, dict)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:BuildShell(dir, env, git, args) abort
|
function! s:BuildShell(dir, env, git, args) abort
|
||||||
@@ -1198,7 +1222,7 @@ function! fugitive#RemoteHttpHeaders(remote) abort
|
|||||||
let url = remote . '/info/refs?service=git-upload-pack'
|
let url = remote . '/info/refs?service=git-upload-pack'
|
||||||
let exec = s:JobExecute(
|
let exec = s:JobExecute(
|
||||||
\ ['curl', '--disable', '--silent', '--max-time', '5', '-X', 'GET', '-I',
|
\ ['curl', '--disable', '--silent', '--max-time', '5', '-X', 'GET', '-I',
|
||||||
\ url], {}, [function('s:CurlResponse')], {})
|
\ url], {}, [], [function('s:CurlResponse')], {})
|
||||||
call fugitive#Wait(exec)
|
call fugitive#Wait(exec)
|
||||||
let s:remote_headers[remote] = exec.headers
|
let s:remote_headers[remote] = exec.headers
|
||||||
endif
|
endif
|
||||||
@@ -3694,7 +3718,7 @@ let s:exec_paths = {}
|
|||||||
function! s:ExecPath() abort
|
function! s:ExecPath() abort
|
||||||
let git = s:GitShellCmd()
|
let git = s:GitShellCmd()
|
||||||
if !has_key(s:exec_paths, git)
|
if !has_key(s:exec_paths, git)
|
||||||
let s:exec_paths[git] = get(s:JobExecute(s:GitCmd() + ['--exec-path'], {}, [], {}).stdout, 0, '')
|
let s:exec_paths[git] = get(s:JobExecute(s:GitCmd() + ['--exec-path'], {}, [], [], {}).stdout, 0, '')
|
||||||
endif
|
endif
|
||||||
return s:exec_paths[git]
|
return s:exec_paths[git]
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user