From 1bd77bec751c0a0f4abfa94004674abb566dbe2b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 21 Aug 2021 21:14:21 -0400 Subject: [PATCH] Include remote_name in :GBrowse options Uses for this are limited, but it does allow for retrieving the raw URL before resolution, or for getting other properties from the remote's Git config. Also, allow FugitiveRemoteUrl(browse_opts) to directly retrieve the URL. --- autoload/fugitive.vim | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 796bfac..8078f85 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1152,6 +1152,9 @@ function! fugitive#RemoteUrl(...) abort if a:0 && (type(a:1) !=# type('') || a:1 =~# '^/\|^\a:[\\/]' && get(a:, 2, '') !~# '^/\|^\a:[\\/]') let config = fugitive#Config(a:1) let args = a:000[1:-1] + if type(a:1) ==# type({}) && has_key(a:1, 'remote_name') && (type(get(args, 0, 0)) !=# type('') || args[0] =~# '^:') + call insert(args, a:1.remote_name) + endif elseif a:0 > 1 let config = fugitive#Config(a:2) let args = [a:1] + a:000[2:-1] @@ -1159,7 +1162,7 @@ function! fugitive#RemoteUrl(...) abort let config = fugitive#Config() let args = copy(a:000) endif - if empty(args) + if empty(args) || args[0] =~# '^:' let url = s:Remote(config) elseif args[0] =~# '^\.\=$' call remove(args, 0) @@ -1185,8 +1188,8 @@ function! fugitive#RemoteUrl(...) abort break endif endfor - if index(args, 1) < 0 && index(args, get(v:, 'true', 1)) < 0 && index(args, 'noresolve') < 0 - let url = fugitive#ResolveRemote(url) + if index(args, 1) < 0 && index(args, get(v:, 'true', 1)) < 0 && index(args, ':noresolve') < 0 + let url = fugitive#ResolveRemote(url).full endif return url endfunction @@ -6984,13 +6987,11 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo endwhile endif - if empty(remote) - let remote = '.' - endif - let raw = fugitive#RemoteUrl(remote, dir) - if empty(raw) - let raw = remote + if empty(remote) || remote ==# '.' + let remote = s:Remote(dir) endif + let remote_url = fugitive#RemoteUrl(remote, dir) + let raw = empty(remote_url) ? remote : remote_url let opts = { \ 'git_dir': dir, @@ -6998,6 +6999,7 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo \ 'repo': fugitive#repo(dir), \ 'remote': raw, \ 'revision': 'No longer provided', + \ 'remote_name': remote, \ 'commit': commit, \ 'path': path, \ 'type': type,