Skip to content

Commit

Permalink
For push map, never push to fetch remote
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tpope committed Mar 4, 2024
1 parent ded6eb9 commit 41beeda
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions autoload/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5158,11 +5158,12 @@ function! s:DoToggleHelpHeader(value) abort
endfunction

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

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

function! s:DoStageUnpushedHeading(heading) abort
let remote = matchstr(a:heading, 'to \zs[^/]\+\ze/')
if empty(remote)
let remote = '.'
endif
let branch = matchstr(a:heading, 'to \%([^/]\+/\)\=\zs\S\+')
if branch ==# '*'
let stat = get(b:, 'fugitive_status', {})
let remote = get(stat, 'push_remote', '')
let push = get(stat, 'push', '')
if empty(remote) || empty(push)
return
endif
call feedkeys(':Git push ' . remote . ' ' . '@:' . 'refs/heads/' . branch)
call feedkeys(':Git push ' . remote . ' ' . '@:' . push)
endfunction

function! s:DoToggleUnpushedHeading(heading) abort
return s:DoStageUnpushedHeading(a:heading)
endfunction

function! s:DoStageUnpushed(record) abort
let remote = matchstr(a:record.heading, 'to \zs[^/]\+\ze/')
if empty(remote)
let remote = '.'
endif
let branch = matchstr(a:record.heading, 'to \%([^/]\+/\)\=\zs\S\+')
if branch ==# '*'
let stat = get(b:, 'fugitive_status', {})
let remote = get(stat, 'push_remote', '')
let push = get(stat, 'push', '')
if empty(remote) || empty(push)
return
endif
call feedkeys(':Git push ' . remote . ' ' . a:record.commit . ':' . 'refs/heads/' . branch)
call feedkeys(':Git push ' . remote . ' ' . a:record.commit . ':' . push)
endfunction

function! s:DoToggleUnpushed(record) abort
Expand Down

0 comments on commit 41beeda

Please sign in to comment.