From 8ede0aaf57e1dbb5416ddbe30d0bfdde762e90bf Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 6 Apr 2021 23:38:18 -0400 Subject: [PATCH] Provide :GBrowse behavior in blame buffers If a line number is given, browse to the commit on that line. Otherwise, browse to the file, same as if called from the original buffer. It would probably make more sense to open the corresponding blame page on providers that support it, but that will have to wait on an API change. References https://github.com/tpope/vim-fugitive/issues/1214 --- autoload/fugitive.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 4c39543..c577bd3 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -5576,7 +5576,10 @@ endfunction function! s:BlameCommitFileLnum(...) abort let line = a:0 ? a:1 : getline('.') - let state = a:0 ? a:2 : s:TempState() + let state = a:0 > 1 ? a:2 : s:TempState() + if get(state, 'filetype', '') !=# 'fugitiveblame' + return ['', '', 0] + endif let commit = matchstr(line, '^\^\=[?*]*\zs\x\+') if commit =~# '^0\+$' let commit = '' @@ -6126,9 +6129,6 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo else let rev = arg endif - if rev ==# '' - let rev = s:DirRev(@%)[1] - endif if rev =~? '^\a\a\+:[\/][\/]' && rev !~? '^fugitive:' let rev = substitute(rev, '\\\@ 0 && bufname !=# bufname('') + let blame = s:BlameCommitFileLnum(getline(a:count)) + if len(blame[0]) + let expanded = blame[0] + endif + endif endif let cdir = FugitiveVimPath(fugitive#CommonDir(dir)) for subdir in ['tags/', 'heads/', 'remotes/']