mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 05:43:52 -05:00
Extract helper to parse fugitive#RemoteUrl() arguments
This commit is contained in:
@@ -1300,27 +1300,49 @@ function! s:ConfigLengthSort(i1, i2) abort
|
|||||||
return len(a:i2[0]) - len(a:i1[0])
|
return len(a:i2[0]) - len(a:i1[0])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! s:RemoteParseArgs(args) abort
|
||||||
let args = copy(a:000)
|
" Extract ':noresolve' style flags and an optional callback
|
||||||
if len(args) && (type(args[0]) !=# type('') || args[0] =~# '^/\|^\a:[\\/]' && get(args, 1, '') !~# '^/\|^\a:[\\/]')
|
let args = []
|
||||||
let config = fugitive#Config(remove(args, 0))
|
let flags = []
|
||||||
if type(a:1) ==# type({}) && has_key(a:1, 'remote_name') && (type(get(args, 0, 0)) !=# type('') || args[0] =~# '^:')
|
let cb = copy(a:args)
|
||||||
call insert(args, a:1.remote_name)
|
while len(cb)
|
||||||
|
if type(cb[0]) ==# type(function('tr'))
|
||||||
|
break
|
||||||
|
elseif len(args) > 1 || type(cb[0]) ==# type('') && cb[0] =~# '^:'
|
||||||
|
call add(flags, remove(cb, 0))
|
||||||
|
else
|
||||||
|
call add(args, remove(cb, 0))
|
||||||
endif
|
endif
|
||||||
elseif len(args) > 1 && (type(args[1]) !=# type('') || args[1] !~# '^:')
|
endwhile
|
||||||
let config = fugitive#Config(remove(args, 1))
|
|
||||||
|
" From the remaining 0-2 arguments, extract the remote and Git config
|
||||||
|
let remote = ''
|
||||||
|
if empty(args)
|
||||||
|
let dir_or_config = s:Dir()
|
||||||
|
elseif len(args) == 1 && type(args[0]) ==# type('') && args[0] !~# '^/\|^\a:[\\/]'
|
||||||
|
let dir_or_config = s:Dir()
|
||||||
|
let remote = args[0]
|
||||||
|
elseif len(args) == 1
|
||||||
|
let dir_or_config = args[0]
|
||||||
|
if type(args[0]) ==# type({}) && has_key(args[0], 'remote_name')
|
||||||
|
let remote = args[0].remote_name
|
||||||
|
endif
|
||||||
|
elseif type(args[1]) !=# type('') || args[1] =~# '^/\|^\a:[\\/]'
|
||||||
|
let dir_or_config = args[1]
|
||||||
|
let remote = args[0]
|
||||||
else
|
else
|
||||||
let config = fugitive#Config()
|
let dir_or_config = args[0]
|
||||||
|
let remote = args[1]
|
||||||
endif
|
endif
|
||||||
if empty(args) || args[0] =~# '^:'
|
return [dir_or_config, remote, flags, cb]
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#RemoteUrl(...) abort
|
||||||
|
let [dir_or_config, url, flags, cb] = s:RemoteParseArgs(a:000)
|
||||||
|
let config = fugitive#Config(dir_or_config)
|
||||||
|
if url =~# '^\.\=$'
|
||||||
let url = s:RemoteDefault(config)
|
let url = s:RemoteDefault(config)
|
||||||
elseif args[0] =~# '^\.\=$'
|
elseif url ==# '.git'
|
||||||
call remove(args, 0)
|
|
||||||
let url = s:RemoteDefault(config)
|
|
||||||
else
|
|
||||||
let url = remove(args, 0)
|
|
||||||
endif
|
|
||||||
if url ==# '.git'
|
|
||||||
let url = s:GitDir(config)
|
let url = s:GitDir(config)
|
||||||
elseif url !~# ':\|^/\|^\.\.\=/'
|
elseif url !~# ':\|^/\|^\.\.\=/'
|
||||||
let url = FugitiveConfigGet('remote.' . url . '.url', config)
|
let url = FugitiveConfigGet('remote.' . url . '.url', config)
|
||||||
|
|||||||
Reference in New Issue
Block a user