From dd01e40106b661022c6dd3aea8843477c7bb460d Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 26 May 2021 08:40:54 -0400 Subject: [PATCH] Use local not upstream branch name for :GBrowse default When I first wrote this code, I believed push.default=upstream to be the One True Way, and I used the upstream as the default branch when one wasn't passed into :GBrowse. Since then, my preferred workflow has shifted to push.default=current, with my upstream pointed at the repository's integration branch (typically master), which means :GBrowse effectively ignores our current branch, which is less than helpful. This change eliminates :GBrowse's use of the upstream tracking branch except in 2 scenarios: * When push.default=upstream * When the current branch has never been pushed (since using the current branch would result in a 404). --- autoload/fugitive.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 23b0dc9..b552251 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -6248,9 +6248,15 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo let remote = r endif if r ==# '.' || r ==# remote - let merge = m - if path =~# '^\.git/refs/heads/.' - let path = '.git/refs/heads/'.merge + let remote_ref = 'refs/remotes/' . remote . '/' . branch + if FugitiveConfigGet('push.default', dir) ==# 'upstream' || + \ !filereadable(FugitiveFind('.git/' . remote_ref)) && s:ChompError(['rev-parse', '--verify', remote_ref, '--'], dir)[1] + let merge = m + if path =~# '^\.git/refs/heads/.' + let path = '.git/refs/heads/'.merge + endif + else + let merge = branch endif endif endif