From ca61174e9d7f5920aeb03072c85db563069b8e31 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 12 Oct 2021 13:55:32 -0400 Subject: [PATCH] Remove leading slash when parsing scpremote:/~user --- autoload/fugitive.vim | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 184592b..6776f3c 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1253,19 +1253,23 @@ endfunction function! s:UrlParse(url) abort let scp_authority = matchstr(a:url, '^[^:/]\+\ze:\%(//\)\@!') if len(scp_authority) && !(has('win32') && scp_authority =~# '^\a:[\/]') - return {'scheme': 'ssh', 'authority': scp_authority, + let url = {'scheme': 'ssh', 'authority': scp_authority, \ 'path': strpart(a:url, len(scp_authority) + 1)} + elseif empty(a:url) + let url = {'scheme': '', 'authority': '', 'path': ''} + else + let match = matchlist(a:url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/.*\)\=\%(#\|$\)') + if empty(match) + let url = {'scheme': 'file', 'authority': '', 'path': a:url} + else + let url = {'scheme': match[1], 'authority': match[2]} + let url.path = empty(match[3]) ? '/' : match[3] + endif endif - let match = matchlist(a:url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/.*\)\=\%(#\|$\)') - if empty(match) - return {'scheme': 'file', 'authority': '', 'path': a:url} + if (url.scheme ==# 'ssh' || url.scheme ==# 'git') && url.path[0:1] ==# '/~' + let url.path = strpart(url.path, 1) endif - 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 + return url endfunction function! s:ResolveRemote(url) abort