Apply insteadOf to raw remote URLs in addition to remote names

This also retools FugitiveRemoteUrl() argument handling to be a bit more
flexible.
This commit is contained in:
Tim Pope
2021-08-07 15:16:15 -04:00
parent 8def00c247
commit 2ee6a48d0b
2 changed files with 36 additions and 20 deletions

View File

@@ -886,26 +886,42 @@ function! s:ConfigLengthSort(i1, i2) abort
endfunction endfunction
function! fugitive#RemoteUrl(...) abort function! fugitive#RemoteUrl(...) abort
let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir() let args = a:000
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1 if a:0 && type(a:1) !=# type('')
if url !~# ':\|^/\|^\.\.\=/' let config = fugitive#Config(a:1)
let config = fugitive#Config(a:0 > 1 ? a:2 : s:Dir()) let args = a:000[1:-1]
let url = FugitiveConfigGet('remote.' . url . '.url', config) elseif a:0 > 1
let instead_of = [] let config = fugitive#Config(a:2)
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config)) let args = [a:1] + a:000[2:-1]
for v in vs else
call add(instead_of, [v, k]) let config = fugitive#Config()
endfor let args = copy(a:000)
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 empty(args)
let url = s:Remote(config)
elseif args[0] =~# '^\.\=$'
call remove(args, 0)
let url = s:Remote(config)
else
let url = remove(args, 0)
endif
if url !~# ':\|^/\|^\.\.\=/'
let url = FugitiveConfigGet('remote.' . url . '.url', config)
endif
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
if !index(args, 1) && !index(args, get(v:, 'true', 1)) && !index(args, 'noresolve')
let url = fugitive#ResolveRemote(url) let url = fugitive#ResolveRemote(url)
endif endif
return url return url

View File

@@ -171,7 +171,7 @@ endfunction
" An optional second argument provides the Git dir, or the buffer number of a " An optional second argument provides the Git dir, or the buffer number of a
" buffer with a Git dir. The default is the current buffer. " buffer with a Git dir. The default is the current buffer.
function! FugitiveRemoteUrl(...) abort function! FugitiveRemoteUrl(...) abort
return fugitive#RemoteUrl(a:0 ? a:1 : '', a:0 > 1 ? a:2 : -1, a:0 > 2 ? a:3 : 0) return call('fugitive#RemoteUrl', a:000)
endfunction endfunction
" FugitiveHead() retrieves the name of the current branch. If the current HEAD " FugitiveHead() retrieves the name of the current branch. If the current HEAD