Match FugitiveRemote() interface to window.location in JS

This commit is contained in:
Tim Pope
2022-02-11 12:45:16 -05:00
parent c29ef11cd6
commit 485ce07c27
2 changed files with 9 additions and 4 deletions

View File

@@ -1254,6 +1254,14 @@ function! s:UrlParse(url) abort
let url.path = empty(match[3]) ? '/' : match[3] let url.path = empty(match[3]) ? '/' : match[3]
endif endif
endif endif
let url.protocol = substitute(url.scheme, '.\zs$', ':', '')
let url.user = matchstr(url.authority, '.\{-\}\ze@', '', '')
let url.host = substitute(url.authority, '.\{-\}@', '', '')
let url.hostname = substitute(url.host, ':\d\+$', '', '')
let url.port = matchstr(url.host, ':\zs\d\+$', '', '')
let url.origin = substitute(url.scheme, '.\zs$', '://', '') . url.host
let url.search = matchstr(url.path, '?.*')
let url.pathname = '/' . matchstr(url.path, '^/\=\zs[^?]*')
if (url.scheme ==# 'ssh' || url.scheme ==# 'git') && url.path[0:1] ==# '/~' if (url.scheme ==# 'ssh' || url.scheme ==# 'git') && url.path[0:1] ==# '/~'
let url.path = strpart(url.path, 1) let url.path = strpart(url.path, 1)
endif endif
@@ -1319,10 +1327,6 @@ function! s:RemoteCallback(config, into, flags, cb) abort
else else
call extend(a:into, s:UrlParse(url)) call extend(a:into, s:UrlParse(url))
endif endif
let a:into.user = matchstr(a:into.authority, '.\{-\}\ze@', '', '')
let a:into.host = substitute(a:into.authority, '.\{-\}@', '', '')
let a:into.hostname = substitute(a:into.host, ':\d\+$', '', '')
let a:into.port = matchstr(a:into.host, ':\zs\d\+$', '', '')
if len(a:cb) if len(a:cb)
call call(a:cb[0], [a:into] + a:cb[1:-1]) call call(a:cb[0], [a:into] + a:cb[1:-1])
endif endif

View File

@@ -217,6 +217,7 @@ endfunction
" * "scheme": "https" " * "scheme": "https"
" * "authority": "user@example.com:1234" " * "authority": "user@example.com:1234"
" * "path": "/repo.git" (for SSH URLs this may be a relative path) " * "path": "/repo.git" (for SSH URLs this may be a relative path)
" * "pathname": "/repo.git" (always coerced to absolute path)
" * "host": "example.com:1234" " * "host": "example.com:1234"
" * "hostname": "example.com" " * "hostname": "example.com"
" * "port": "1234" " * "port": "1234"