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