mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-09 03:53:47 -05:00
Normalize path when parsing remote URL
Change an empty path to "/" as is the standard interpretation. And for git:// and ssh:// URLs, change a leading "/~" to "~", like Git itself does.
This commit is contained in:
@@ -1247,33 +1247,35 @@ function! fugitive#RemoteHttpHeaders(remote) abort
|
|||||||
return s:remote_headers[remote]
|
return s:remote_headers[remote]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ResolveRemote(url) abort
|
function! s:UrlParse(url) abort
|
||||||
let url = a:url
|
let scp_authority = matchstr(a:url, '^[^:/]\+\ze:\%(//\)\@!')
|
||||||
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 remote.scheme = 'ssh'
|
return {'scheme': 'ssh', 'authority': scp_authority,
|
||||||
let remote.path = strpart(url, len(scp_authority) + 1)
|
\ 'path': strpart(url, len(scp_authority) + 1)}
|
||||||
let remote.authority = fugitive#SshHostAlias(scp_authority)
|
endif
|
||||||
return remote
|
let match = matchlist(a:url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/.*\)\=\%(#\|$\)')
|
||||||
elseif empty(url)
|
if empty(match)
|
||||||
return {'scheme': '', 'authority': '', 'path': ''}
|
return {'scheme': 'file', 'authority': '', 'path': a:url}
|
||||||
elseif url =~# '^https\=://'
|
endif
|
||||||
let headers = fugitive#RemoteHttpHeaders(url)
|
let remote = {'scheme': match[1], 'authority': match[2]}
|
||||||
|
let remote.path = empty(match[3]) ? '/' : match[3]
|
||||||
|
if (remote.scheme ==# 'ssh' || remote.scheme ==# 'git') && remote.path[0:1] ==# '/~'
|
||||||
|
let remote.path = strpart(remote.path, 1)
|
||||||
|
endif
|
||||||
|
return remote
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ResolveRemote(url) abort
|
||||||
|
let remote = s:UrlParse(a:url)
|
||||||
|
if remote.scheme =~# '^https\=$'
|
||||||
|
let headers = fugitive#RemoteHttpHeaders(remote.scheme . '://' . remote.authority . remote.path)
|
||||||
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)
|
||||||
let url = loc
|
let remote = s:UrlParse(loc)
|
||||||
else
|
else
|
||||||
let remote.http_headers = headers
|
let remote.http_headers = headers
|
||||||
endif
|
endif
|
||||||
endif
|
elseif remote.scheme ==# 'ssh'
|
||||||
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)
|
let remote.authority = fugitive#SshHostAlias(remote.authority)
|
||||||
endif
|
endif
|
||||||
return remote
|
return remote
|
||||||
|
|||||||
Reference in New Issue
Block a user