mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 04:53:45 -05:00
Separate remote resolution from URL reassembly
This commit is contained in:
@@ -1247,29 +1247,51 @@ function! fugitive#RemoteHttpHeaders(remote) abort
|
|||||||
return s:remote_headers[remote]
|
return s:remote_headers[remote]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ResolveRemote(remote) abort
|
function! s:ResolveRemote(url) abort
|
||||||
let scp_authority = matchstr(a:remote, '^[^:/]\+\ze:\%(//\)\@!')
|
let url = a:url
|
||||||
|
let scp_authority = matchstr(url, '^[^:/]\+\ze:\%(//\)\@!')
|
||||||
|
let remote = {}
|
||||||
if len(scp_authority) && !(has('win32') && scp_authority =~# '^\a:[\/]')
|
if len(scp_authority) && !(has('win32') && scp_authority =~# '^\a:[\/]')
|
||||||
let path = strpart(a:remote, len(scp_authority) + 1)
|
let remote.scheme = 'ssh'
|
||||||
let authority = fugitive#SshHostAlias(scp_authority)
|
let remote.path = strpart(url, len(scp_authority) + 1)
|
||||||
if path =~# '^/'
|
let remote.authority = fugitive#SshHostAlias(scp_authority)
|
||||||
return 'ssh://' . authority . path
|
return remote
|
||||||
elseif path =~# '^\~'
|
elseif empty(url)
|
||||||
return 'ssh://' . authority . '/' . path
|
return {'scheme': '', 'authority': '', 'path': ''}
|
||||||
elseif authority !~# ':'
|
elseif url =~# '^https\=://'
|
||||||
return authority . ':' . path
|
let headers = fugitive#RemoteHttpHeaders(url)
|
||||||
endif
|
|
||||||
elseif a:remote =~# '^https\=://'
|
|
||||||
let headers = fugitive#RemoteHttpHeaders(a:remote)
|
|
||||||
let loc = matchstr(get(headers, 'location', ''), '^https\=://.\{-\}\ze/info/refs?')
|
let loc = matchstr(get(headers, 'location', ''), '^https\=://.\{-\}\ze/info/refs?')
|
||||||
if len(loc)
|
if len(loc)
|
||||||
return loc
|
let url = loc
|
||||||
|
else
|
||||||
|
let remote.http_headers = headers
|
||||||
endif
|
endif
|
||||||
elseif a:remote =~# '^ssh://'
|
|
||||||
let authority = matchstr(a:remote, '[^/?#]*', 6)
|
|
||||||
return 'ssh://' . fugitive#SshHostAlias(authority) . strpart(a:remote, 6 + len(authority))
|
|
||||||
endif
|
endif
|
||||||
return a:remote
|
let match = matchlist(url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/.*\)\=\%(#\|$\)')
|
||||||
|
if len(match)
|
||||||
|
let [remote.scheme, remote.authority, remote.path] = match[1:3]
|
||||||
|
else
|
||||||
|
return {'scheme': 'file', 'authority': '', 'path': url}
|
||||||
|
endif
|
||||||
|
if remote.scheme ==# 'ssh'
|
||||||
|
let remote.authority = fugitive#SshHostAlias(remote.authority)
|
||||||
|
endif
|
||||||
|
return remote
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#ResolveRemote(url) abort
|
||||||
|
let remote = s:ResolveRemote(a:url)
|
||||||
|
if remote.scheme ==# 'file' || remote.scheme ==# ''
|
||||||
|
return remote.path
|
||||||
|
elseif remote.path =~# '^/'
|
||||||
|
return remote.scheme . '://' . remote.authority . remote.path
|
||||||
|
elseif remote.path =~# '^\~'
|
||||||
|
return remote.scheme . '://' . remote.authority . '/' . remote.path
|
||||||
|
elseif remote.scheme ==# 'ssh' && remote.authority !~# ':'
|
||||||
|
return remote.authority . ':' . remote.path
|
||||||
|
else
|
||||||
|
return a:url
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ConfigLengthSort(i1, i2) abort
|
function! s:ConfigLengthSort(i1, i2) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user