mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 04:23:46 -05:00
Don't rely on current buffer's Git dir for :GBrowse
This makes :GBrowse fugitive://... work when the buffer name is from a different repository. It doesn't solve the harder problems of making it work with a regular filename, or making it not bail early when the current buffer doesn't belong to a repository at all.
This commit is contained in:
@@ -6151,12 +6151,12 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
let full = fugitive#Find(expanded, dir)
|
let full = fugitive#Find(expanded, dir)
|
||||||
let commit = ''
|
let commit = ''
|
||||||
if full =~? '^fugitive:'
|
if full =~? '^fugitive:'
|
||||||
let [pathdir, commit, path] = s:DirCommitFile(full)
|
let [dir, commit, path] = s:DirCommitFile(full)
|
||||||
if commit =~# '^:\=\d$'
|
if commit =~# '^:\=\d$'
|
||||||
let commit = ''
|
let commit = ''
|
||||||
endif
|
endif
|
||||||
if commit =~ '..'
|
if commit =~ '..'
|
||||||
let type = s:TreeChomp('cat-file','-t',commit.s:sub(path,'^/',':'))
|
let type = s:TreeChomp(['cat-file','-t',commit.s:sub(path,'^/',':')], dir)
|
||||||
let branch = matchstr(expanded, '^[^:]*')
|
let branch = matchstr(expanded, '^[^:]*')
|
||||||
else
|
else
|
||||||
let type = 'blob'
|
let type = 'blob'
|
||||||
@@ -6201,16 +6201,16 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
elseif path =~# '^\.git/refs/heads/.'
|
elseif path =~# '^\.git/refs/heads/.'
|
||||||
let branch = path[16:-1]
|
let branch = path[16:-1]
|
||||||
elseif !exists('branch')
|
elseif !exists('branch')
|
||||||
let branch = FugitiveHead()
|
let branch = FugitiveHead(0, dir)
|
||||||
endif
|
endif
|
||||||
if !empty(branch)
|
if !empty(branch)
|
||||||
let r = fugitive#Config('branch.'.branch.'.remote')
|
let r = FugitiveConfigGet('branch.'.branch.'.remote', dir)
|
||||||
let m = fugitive#Config('branch.'.branch.'.merge')[11:-1]
|
let m = FugitiveConfigGet('branch.'.branch.'.merge', dir)[11:-1]
|
||||||
if r ==# '.' && !empty(m)
|
if r ==# '.' && !empty(m)
|
||||||
let r2 = fugitive#Config('branch.'.m.'.remote')
|
let r2 = FugitiveConfigGet('branch.'.m.'.remote', dir)
|
||||||
if r2 !~# '^\.\=$'
|
if r2 !~# '^\.\=$'
|
||||||
let r = r2
|
let r = r2
|
||||||
let m = fugitive#Config('branch.'.m.'.merge')[11:-1]
|
let m = FugitiveConfigGet('branch.'.m.'.merge', dir)[11:-1]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if empty(remote)
|
if empty(remote)
|
||||||
@@ -6232,8 +6232,8 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
else
|
else
|
||||||
let commit = ''
|
let commit = ''
|
||||||
if len(merge)
|
if len(merge)
|
||||||
let owner = s:Owner(@%)
|
let owner = s:Owner(@%, dir)
|
||||||
let [commit, exec_error] = s:ChompError(['merge-base', 'refs/remotes/' . remote . '/' . merge, empty(owner) ? 'HEAD' : owner, '--'])
|
let [commit, exec_error] = s:ChompError(['merge-base', 'refs/remotes/' . remote . '/' . merge, empty(owner) ? 'HEAD' : owner, '--'], dir)
|
||||||
if exec_error
|
if exec_error
|
||||||
let commit = ''
|
let commit = ''
|
||||||
endif
|
endif
|
||||||
@@ -6242,7 +6242,7 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
call writefile([commit, ''], blame_list, 'b')
|
call writefile([commit, ''], blame_list, 'b')
|
||||||
let blame_in = tempname()
|
let blame_in = tempname()
|
||||||
silent exe '%write' blame_in
|
silent exe '%write' blame_in
|
||||||
let [blame, exec_error] = s:LinesError(['-c', 'blame.coloring=none', 'blame', '--contents', blame_in, '-L', line1.','.line2, '-S', blame_list, '-s', '--show-number', './' . path])
|
let [blame, exec_error] = s:LinesError(['-c', 'blame.coloring=none', 'blame', '--contents', blame_in, '-L', line1.','.line2, '-S', blame_list, '-s', '--show-number', './' . path], dir)
|
||||||
if !exec_error
|
if !exec_error
|
||||||
let blame_regex = '^\^\x\+\s\+\zs\d\+\ze\s'
|
let blame_regex = '^\^\x\+\s\+\zs\d\+\ze\s'
|
||||||
if get(blame, 0) =~# blame_regex && get(blame, -1) =~# blame_regex
|
if get(blame, 0) =~# blame_regex && get(blame, -1) =~# blame_regex
|
||||||
@@ -6273,7 +6273,7 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
|||||||
if empty(remote)
|
if empty(remote)
|
||||||
let remote = '.'
|
let remote = '.'
|
||||||
endif
|
endif
|
||||||
let raw = fugitive#RemoteUrl(remote)
|
let raw = fugitive#RemoteUrl(remote, dir)
|
||||||
if empty(raw)
|
if empty(raw)
|
||||||
let raw = remote
|
let raw = remote
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user