commit 8ede0aaf57e1dbb5416ddbe30d0bfdde762e90bf (tree)
parent 3a319cd5b83ce1d5ba85561dd1bbe71dd930606d
Author: Tim Pope <code@tpope.net>
Date: Tue, 6 Apr 2021 23:38:18 -0400
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
Diffstat:
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git 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, '\\\@<![#!]\|\\\@<!%\ze\w', '\\&', 'g')
elseif rev ==# ':'
@@ -6140,7 +6140,17 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
endif
exe s:DirCheck(dir)
if empty(expanded)
- let expanded = s:Relative(':(top)', dir)
+ let bufname = s:BufName('%')
+ let expanded = s:DirRev(bufname)[1]
+ if empty(expanded)
+ let expanded = fugitive#Path(bufname, ':(top)', dir)
+ endif
+ if a:count > 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/']