mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 05:43:52 -05:00
Get remote URL with config rather than shelling out
This commit is contained in:
@@ -852,15 +852,29 @@ function! fugitive#ResolveRemote(remote) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:ConfigLengthSort(i1, i2) abort
|
||||||
|
return len(a:i2[0]) - len(a:i1[0])
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir()
|
let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir()
|
||||||
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
||||||
if url !~# ':\|^/\|^\.\.\=/'
|
if url !~# ':\|^/\|^\.\.\=/'
|
||||||
if !fugitive#GitVersion(2, 7)
|
let config = fugitive#Config(a:0 > 1 ? a:2 : s:Dir())
|
||||||
let url = FugitiveConfigGet('remote.' . url . '.url')
|
let url = FugitiveConfigGet('remote.' . url . '.url', config)
|
||||||
else
|
let instead_of = []
|
||||||
let url = s:ChompDefault('', [dir, 'remote', 'get-url', url, '--'])
|
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config))
|
||||||
endif
|
for v in vs
|
||||||
|
call add(instead_of, [v, k])
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
call sort(instead_of, 's:ConfigLengthSort')
|
||||||
|
for [orig, replacement] in instead_of
|
||||||
|
if strpart(url, 0, len(orig)) ==# orig
|
||||||
|
let url = replacement . strpart(url, len(orig))
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
if !get(a:, 3, 0)
|
if !get(a:, 3, 0)
|
||||||
let url = fugitive#ResolveRemote(url)
|
let url = fugitive#ResolveRemote(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user