commit a41329ab7c3afa5ead4194f761b9d07b20b5bb49 (tree)
parent 5f8762227784100a4d30351bdd4baccdc45a4d7c
Author: Tim Pope <code@tpope.net>
Date: Mon, 26 Jul 2021 07:53:29 -0400
Get remote URL with config rather than shelling out
Diffstat:
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git 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)