Skip to content

Commit 41beeda

Browse files
committed
For push map, never push to fetch remote
There are legitimate reasons to push to the fetch remote, but making it possible from the push map makes it too easy to do by default.
1 parent ded6eb9 commit 41beeda

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

autoload/fugitive.vim

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,11 +5158,12 @@ function! s:DoToggleHelpHeader(value) abort
51585158
endfunction
51595159

51605160
function! s:DoStagePushHeader(value) abort
5161-
let remote = matchstr(a:value, '\zs[^/]\+\ze/')
5162-
if empty(remote)
5163-
let remote = '.'
5161+
let stat = get(b:, 'fugitive_status', {})
5162+
let remote = get(stat, 'push_remote', '')
5163+
let branch = substitute(get(stat, 'push', ''), '^ref/heads/', '', '')
5164+
if empty(remote) || empty(branch)
5165+
return
51645166
endif
5165-
let branch = matchstr(a:value, '\%([^/]\+/\)\=\zs\S\+')
51665167
call feedkeys(':Git push ' . remote . ' ' . branch)
51675168
endfunction
51685169

@@ -5171,31 +5172,27 @@ function! s:DoTogglePushHeader(value) abort
51715172
endfunction
51725173

51735174
function! s:DoStageUnpushedHeading(heading) abort
5174-
let remote = matchstr(a:heading, 'to \zs[^/]\+\ze/')
5175-
if empty(remote)
5176-
let remote = '.'
5177-
endif
5178-
let branch = matchstr(a:heading, 'to \%([^/]\+/\)\=\zs\S\+')
5179-
if branch ==# '*'
5175+
let stat = get(b:, 'fugitive_status', {})
5176+
let remote = get(stat, 'push_remote', '')
5177+
let push = get(stat, 'push', '')
5178+
if empty(remote) || empty(push)
51805179
return
51815180
endif
5182-
call feedkeys(':Git push ' . remote . ' ' . '@:' . 'refs/heads/' . branch)
5181+
call feedkeys(':Git push ' . remote . ' ' . '@:' . push)
51835182
endfunction
51845183

51855184
function! s:DoToggleUnpushedHeading(heading) abort
51865185
return s:DoStageUnpushedHeading(a:heading)
51875186
endfunction
51885187

51895188
function! s:DoStageUnpushed(record) abort
5190-
let remote = matchstr(a:record.heading, 'to \zs[^/]\+\ze/')
5191-
if empty(remote)
5192-
let remote = '.'
5193-
endif
5194-
let branch = matchstr(a:record.heading, 'to \%([^/]\+/\)\=\zs\S\+')
5195-
if branch ==# '*'
5189+
let stat = get(b:, 'fugitive_status', {})
5190+
let remote = get(stat, 'push_remote', '')
5191+
let push = get(stat, 'push', '')
5192+
if empty(remote) || empty(push)
51965193
return
51975194
endif
5198-
call feedkeys(':Git push ' . remote . ' ' . a:record.commit . ':' . 'refs/heads/' . branch)
5195+
call feedkeys(':Git push ' . remote . ' ' . a:record.commit . ':' . push)
51995196
endfunction
52005197

52015198
function! s:DoToggleUnpushed(record) abort

0 commit comments

Comments
 (0)