diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index a1776ed..45fff01 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -68,6 +68,15 @@ function! s:shellslash(path) abort endif endfunction +let s:executables = {} + +function! s:executable(binary) abort + if !has_key(s:executables, a:binary) + let s:executables[a:binary] = executable(a:binary) + endif + return s:executables[a:binary] +endfunction + let s:git_versions = {} function! s:git_command() abort @@ -2228,6 +2237,8 @@ endfunction call s:command("-bar -bang -range=0 -nargs=* -complete=customlist,s:EditComplete Gbrowse :execute s:Browse(0,,,)") +let s:redirects = {} + function! s:Browse(bang,line1,count,...) abort try let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\=' @@ -2342,6 +2353,17 @@ function! s:Browse(bang,line1,count,...) abort let raw = remote 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 + for Handler in g:fugitive_browse_handlers let url = call(Handler, [{ \ 'repo': s:repo(),