diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 9f14a4b..04ed1e9 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -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.\+')