Support :GBrowse with paths outside current repo

Resolves: https://github.com/tpope/vim-fugitive/issues/2144
This commit is contained in:
Tim Pope
2023-03-30 10:38:32 -04:00
parent 9acbad1335
commit ef99f1d90c

View File

@@ -7379,11 +7379,12 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, ...) abor
endfor
return 'echoerr ' . string('fugitive: no URL found in output of :Git')
endif
exe s:DirCheck(dir)
let config = fugitive#Config(dir)
if empty(remote) && expanded =~# '^[^-./:^~][^:^~]*$' && !empty(FugitiveConfigGet('remote.' . expanded . '.url', config))
let remote = expanded
let expanded = ''
if empty(remote) && expanded =~# '^[^-./:^~][^:^~]*$' && !empty(dir)
let config = fugitive#Config(dir)
if !empty(FugitiveConfigGet('remote.' . expanded . '.url', config))
let remote = expanded
let expanded = ''
endif
endif
if empty(expanded)
let bufname = &buftype =~# '^\%(nofile\|terminal\)$' ? '' : s:BufName('%')
@@ -7419,17 +7420,22 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, ...) abor
endif
endif
let path = path[1:-1]
elseif empty(s:Tree(dir))
let path = '.git/' . full[strlen(dir)+1:-1]
let type = ''
else
let path = fugitive#Path(full, '/')[1:-1]
elseif !empty(s:Tree(dir))
let relevant_dir = FugitiveExtractGitDir(full)
if !empty(relevant_dir)
let dir = relevant_dir
endif
let path = fugitive#Path(full, '/', dir)[1:-1]
if empty(path) || isdirectory(full)
let type = 'tree'
else
let type = 'blob'
endif
else
let path = '.git/' . full[strlen(dir)+1:-1]
let type = ''
endif
exe s:DirCheck(dir)
if path =~# '^\.git/'
let ref = matchstr(path, '^.git/\zs\%(refs/[^/]\+/[^/].*\|\w*HEAD\)$')
let type = empty(ref) ? 'root': 'ref'
@@ -7447,6 +7453,9 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, ...) abor
endif
endif
if !exists('l:config') || s:Dir(config) !=# dir
let config = fugitive#Config(dir)
endif
let merge = ''
if !empty(remote) && ref =~# '^refs/remotes/[^/]\+/[^/]\|^refs/heads/[^/]'
let merge = matchstr(ref, '^refs/\%(heads/\|remotes/[^/]\+/\)\zs.\+')