mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-12-10 22:11:58 +08:00
Adjust :Gbrowse range for upstream head
This commit is contained in:
@@ -3074,17 +3074,42 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let line1 = a:count > 0 ? a:line1 : 0
|
||||||
|
let line2 = a:count > 0 ? a:count : 0
|
||||||
if empty(commit) && path !~# '^\.git/'
|
if empty(commit) && path !~# '^\.git/'
|
||||||
if a:line1 && !a:count && !empty(merge)
|
if a:line1 && !a:count && !empty(merge)
|
||||||
let commit = merge
|
let commit = merge
|
||||||
else
|
else
|
||||||
let commit = readfile(b:git_dir . '/HEAD', '', 1)[0]
|
let commit = ''
|
||||||
let i = 0
|
if len(merge)
|
||||||
while commit =~# '^ref: ' && i < 10
|
let remotehead = cdir . '/refs/remotes/' . remote . '/' . merge
|
||||||
let commit = readfile(cdir . '/' . commit[5:-1], '', 1)[0]
|
let commit = filereadable(remotehead) ? get(readfile(remotehead), 0, '') : ''
|
||||||
let i -= 1
|
if a:count && !a:0 && commit =~# '^\x\{40\}$'
|
||||||
endwhile
|
let blame_list = s:tempname()
|
||||||
|
call writefile([commit, ''], blame_list, 'b')
|
||||||
|
let blame_in = s:tempname()
|
||||||
|
silent exe '%write' . blame_in
|
||||||
|
let blame = split(s:TreeChomp('blame', '--contents', blame_in, '-L', a:line1.','.a:count, '-S', blame_list, '-s', '--show-number', '--', path), "\n")
|
||||||
|
if !v:shell_error
|
||||||
|
let blame_regex = '^\^\x\+\s\+\zs\d\+\ze\s'
|
||||||
|
if get(blame, 0) =~# blame_regex && get(blame, -1) =~# blame_regex
|
||||||
|
let line1 = +matchstr(blame[0], blame_regex)
|
||||||
|
let line2 = +matchstr(blame[-1], blame_regex)
|
||||||
|
else
|
||||||
|
call s:throw("Can't browse to uncommitted change")
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
if empty(commit)
|
||||||
|
let commit = readfile(b:git_dir . '/HEAD', '', 1)[0]
|
||||||
|
endif
|
||||||
|
let i = 0
|
||||||
|
while commit =~# '^ref: ' && i < 10
|
||||||
|
let commit = readfile(cdir . '/' . commit[5:-1], '', 1)[0]
|
||||||
|
let i -= 1
|
||||||
|
endwhile
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(remote)
|
if empty(remote)
|
||||||
@@ -3114,8 +3139,8 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
\ 'commit': commit,
|
\ 'commit': commit,
|
||||||
\ 'path': path,
|
\ 'path': path,
|
||||||
\ 'type': type,
|
\ 'type': type,
|
||||||
\ 'line1': a:count > 0 ? a:line1 : 0,
|
\ 'line1': line1,
|
||||||
\ 'line2': a:count > 0 ? a:count : 0}
|
\ 'line2': line2}
|
||||||
|
|
||||||
for Handler in get(g:, 'fugitive_browse_handlers', [])
|
for Handler in get(g:, 'fugitive_browse_handlers', [])
|
||||||
let url = call(Handler, [copy(opts)])
|
let url = call(Handler, [copy(opts)])
|
||||||
|
|||||||
Reference in New Issue
Block a user