mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 05:43:52 -05:00
Unify remote resolution
HTTP redirects and SSH host aliases are just different manifestations of the same indirection, so handle them both in FugitiveRemoteUrl(). Also make this function idempotent if a URL is passed in, and pass some sensible options to cURL.
This commit is contained in:
@@ -659,18 +659,37 @@ function! fugitive#SshHostAlias(...) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let s:redirects = {}
|
||||||
|
|
||||||
|
function! fugitive#ResolveRemote(remote) abort
|
||||||
|
if a:remote =~# '^https\=://' && s:executable('curl')
|
||||||
|
if !has_key(s:redirects, a:remote)
|
||||||
|
let s:redirects[a:remote] = matchstr(s:SystemError(
|
||||||
|
\ 'curl --disable --silent --max-time 5 -I ' .
|
||||||
|
\ s:shellesc(a:remote . '/info/refs?service=git-upload-pack'))[0],
|
||||||
|
\ 'Location: \zs\S\+\ze/info/refs?')
|
||||||
|
endif
|
||||||
|
if len(s:redirects[a:remote])
|
||||||
|
return s:redirects[a:remote]
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return substitute(a:remote,
|
||||||
|
\ '^ssh://\%([^@:/]\+@\)\=\zs[^/:]\+\|^\%([^@:/]\+@\)\=\zs[^/:]\+\ze:/\@!',
|
||||||
|
\ '\=fugitive#SshHostAlias(submatch(0))', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : s:Dir()
|
let dir = a:0 > 1 ? a:2 : s:Dir()
|
||||||
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
||||||
if !fugitive#GitVersion(2, 7)
|
if url !~# ':\|^/\|^\.\.\=/'
|
||||||
let url = FugitiveConfigGet('remote.' . remote . '.url')
|
if !fugitive#GitVersion(2, 7)
|
||||||
else
|
let url = FugitiveConfigGet('remote.' . url . '.url')
|
||||||
let url = s:ChompDefault('', [dir, 'remote', 'get-url', remote, '--'])
|
else
|
||||||
|
let url = s:ChompDefault('', [dir, 'remote', 'get-url', url, '--'])
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
if !get(a:, 3, 0)
|
if !get(a:, 3, 0)
|
||||||
let url = substitute(url,
|
let url = fugitive#ResolveRemote(url)
|
||||||
\ '^ssh://\%([^@:/]\+@\)\=\zs[^/:]\+\|^\%([^@:/]\+@\)\=\zs[^/:]\+\ze:/\@!',
|
|
||||||
\ '\=fugitive#SshHostAlias(submatch(0))', '')
|
|
||||||
endif
|
endif
|
||||||
return url
|
return url
|
||||||
endfunction
|
endfunction
|
||||||
@@ -5859,8 +5878,6 @@ augroup END
|
|||||||
|
|
||||||
" Section: :GBrowse
|
" Section: :GBrowse
|
||||||
|
|
||||||
let s:redirects = {}
|
|
||||||
|
|
||||||
function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abort
|
function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abort
|
||||||
let dir = s:Dir()
|
let dir = s:Dir()
|
||||||
exe s:DirCheck(dir)
|
exe s:DirCheck(dir)
|
||||||
@@ -6032,17 +6049,6 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
let raw = remote
|
let raw = remote
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if raw =~# '^https\=://' && s:executable('curl')
|
|
||||||
if !has_key(s:redirects, raw)
|
|
||||||
let s:redirects[raw] = matchstr(system('curl -I ' .
|
|
||||||
\ s:shellesc(raw . '/info/refs?service=git-upload-pack')),
|
|
||||||
\ 'Location: \zs\S\+\ze/info/refs?')
|
|
||||||
endif
|
|
||||||
if len(s:redirects[raw])
|
|
||||||
let raw = s:redirects[raw]
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
let opts = {
|
let opts = {
|
||||||
\ 'dir': dir,
|
\ 'dir': dir,
|
||||||
\ 'repo': fugitive#repo(dir),
|
\ 'repo': fugitive#repo(dir),
|
||||||
|
|||||||
Reference in New Issue
Block a user