Fix handling of Include in SSH config

The Include directive behaves very literally.  The old implementation
assumed a level of encapsulation that just doesn't match the actual
implementation.
This commit is contained in:
Tim Pope
2023-12-22 21:04:46 -05:00
parent ac673f1e08
commit ec8f7eed10

View File

@@ -1235,12 +1235,15 @@ function! s:SshParseHost(value) abort
return '^\%(' . join(patterns, '\|') . '\)$' . join(negates, '')
endfunction
function! s:SshParseConfig(into, root, file, ...) abort
if !filereadable(a:file)
function! s:SshParseConfig(into, root, file) abort
try
let lines = readfile(a:file)
catch
return a:into
endif
let host = a:0 ? a:1 : '^\%(.*\)$'
for line in readfile(a:file)
endtry
let host = '^\%(.*\)$'
while !empty(lines)
let line = remove(lines, 0)
let key = tolower(matchstr(line, '^\s*\zs\w\+\ze\s'))
let value = matchstr(line, '^\s*\w\+\s\+\zs.*\S')
if key ==# 'match'
@@ -1248,26 +1251,22 @@ function! s:SshParseConfig(into, root, file, ...) abort
elseif key ==# 'host'
let host = s:SshParseHost(value)
elseif key ==# 'include'
call s:SshParseInclude(a:into, a:root, host, value)
for glob in split(value)
if glob !~# '^/'
let glob = a:root . glob
endif
for included in reverse(split(glob(glob), "\n"))
call extend(lines, readfile(included), 'keep')
endfor
endfor
elseif len(key) && len(host)
call extend(a:into, {key : []}, 'keep')
call add(a:into[key], [host, value])
endif
endfor
endwhile
return a:into
endfunction
function! s:SshParseInclude(into, root, host, value) abort
for glob in split(a:value)
if glob !~# '^/'
let glob = a:root . glob
endif
for file in split(glob(glob), "\n")
call s:SshParseConfig(a:into, a:root, file, a:host)
endfor
endfor
endfunction
unlet! s:ssh_config
function! fugitive#SshConfig(host, ...) abort
if !exists('s:ssh_config')