commit 2ee6a48d0bb7fa10040d0165583895cf4761206e (tree)
parent 8def00c247ca0e298977fed1a3b04ac1657bfc67
Author: Tim Pope <code@tpope.net>
Date: Sat, 7 Aug 2021 15:16:15 -0400
Apply insteadOf to raw remote URLs in addition to remote names
This also retools FugitiveRemoteUrl() argument handling to be a bit more
flexible.
Diffstat:
2 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -886,26 +886,42 @@ function! s:ConfigLengthSort(i1, i2) abort
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
+ let args = a:000
+ 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 !~# ':\|^/\|^\.\.\=/'
- 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 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)
endif
return url
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -171,7 +171,7 @@ endfunction
" 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.
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
" FugitiveHead() retrieves the name of the current branch. If the current HEAD