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,11 +886,28 @@ 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('')
let config = fugitive#Config(a:1)
let args = a:000[1:-1]
elseif a:0 > 1
let config = fugitive#Config(a:2)
let args = [a:1] + a:000[2:-1]
else
let config = fugitive#Config()
let args = copy(a:000)
endif
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 !~# ':\|^/\|^\.\.\=/' if url !~# ':\|^/\|^\.\.\=/'
let config = fugitive#Config(a:0 > 1 ? a:2 : s:Dir())
let url = FugitiveConfigGet('remote.' . url . '.url', config) let url = FugitiveConfigGet('remote.' . url . '.url', config)
endif
let instead_of = [] let instead_of = []
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config)) for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config))
for v in vs for v in vs
@@ -904,8 +921,7 @@ function! fugitive#RemoteUrl(...) abort
break break
endif endif
endfor endfor
endif if !index(args, 1) && !index(args, get(v:, 'true', 1)) && !index(args, 'noresolve')
if !get(a:, 3, 0)
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