From a41329ab7c3afa5ead4194f761b9d07b20b5bb49 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 26 Jul 2021 07:53:29 -0400 Subject: [PATCH] Get remote URL with config rather than shelling out --- autoload/fugitive.vim | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 0b13c81..2176401 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -852,15 +852,29 @@ function! fugitive#ResolveRemote(remote) abort endif endfunction +function! s:ConfigLengthSort(i1, i2) abort + return len(a:i2[0]) - len(a:i1[0]) +endfunction + function! fugitive#RemoteUrl(...) abort let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir() let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1 if url !~# ':\|^/\|^\.\.\=/' - if !fugitive#GitVersion(2, 7) - let url = FugitiveConfigGet('remote.' . url . '.url') - else - let url = s:ChompDefault('', [dir, 'remote', 'get-url', url, '--']) - endif + let config = fugitive#Config(a:0 > 1 ? a:2 : s:Dir()) + let url = FugitiveConfigGet('remote.' . url . '.url', config) + let instead_of = [] + for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config)) + 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 if !get(a:, 3, 0) let url = fugitive#ResolveRemote(url)