Make push map available on P

I think matching the Magit interface is probably a better use of P than
wrapping --patch.  As a baby step in that direction, allow P to invoke
the same experimental behavior as "s" or "-".
This commit is contained in:
Tim Pope
2024-03-02 15:08:49 -05:00
parent a0b0c1ddc1
commit 5a9bd42dd8
2 changed files with 17 additions and 6 deletions

View File

@@ -2714,10 +2714,10 @@ function! s:MapStatus() abort
call s:Map('n', 'd?', ":<C-U>help fugitive_d<CR>", '<silent>')
call s:Map('n', 'P', ":<C-U>execute <SID>StagePatch(line('.'),line('.')+v:count1-1)<CR>", '<silent>')
call s:Map('x', 'P', ":<C-U>execute <SID>StagePatch(line(\"'<\"),line(\"'>\"))<CR>", '<silent>')
call s:Map('n', 'p', ":<C-U>if v:count<Bar>silent exe <SID>GF('pedit')<Bar>else<Bar>echoerr 'Use = for inline diff, P for :Git add/reset --patch, 1p for :pedit'<Bar>endif<CR>", '<silent>')
call s:Map('n', 'p', ":<C-U>if v:count<Bar>silent exe <SID>GF('pedit')<Bar>else<Bar>echoerr 'Use = for inline diff, I for :Git add/reset --patch, 1p for :pedit'<Bar>endif<CR>", '<silent>')
call s:Map('x', 'p', ":<C-U>execute <SID>StagePatch(line(\"'<\"),line(\"'>\"))<CR>", '<silent>')
call s:Map('n', 'I', ":<C-U>execute <SID>StagePatch(line('.'),line('.'))<CR>", '<silent>')
call s:Map('x', 'I', ":<C-U>execute <SID>StagePatch(line(\"'<\"),line(\"'>\"))<CR>", '<silent>')
call s:Map('n', 'I', ":<C-U>execute <SID>StagePatch(line('.'),line('.'), 1)<CR>", '<silent>')
call s:Map('x', 'I', ":<C-U>execute <SID>StagePatch(line(\"'<\"),line(\"'>\"), 1)<CR>", '<silent>')
call s:Map('n', 'gq', ":<C-U>if bufnr('$') == 1<Bar>quit<Bar>else<Bar>bdelete<Bar>endif<CR>", '<silent>')
call s:Map('n', 'R', ":echohl WarningMsg<Bar>echo 'Reloading is automatic. Use :e to force'<Bar>echohl NONE<CR>", '<silent>')
call s:Map('n', 'g<Bar>', ":<C-U>echoerr 'Changed to X'<CR>", '<silent><unique>')
@@ -5303,10 +5303,11 @@ function! s:DoStageUntracked(record) abort
return s:DoToggleUntracked(a:record)
endfunction
function! s:StagePatch(lnum1,lnum2) abort
function! s:StagePatch(lnum1, lnum2, ...) abort
let add = []
let reset = []
let intend = []
let patch_only = a:0 && a:1
for lnum in range(a:lnum1,a:lnum2)
let info = s:StageInfo(lnum)
@@ -5319,6 +5320,13 @@ function! s:StagePatch(lnum1,lnum2) abort
elseif empty(info.paths) && info.section ==# 'Untracked'
execute 'tab Git add --interactive'
break
elseif !patch_only && info.section ==# 'Unpushed'
if empty(info.commit)
call s:DoStageUnpushedHeading(info)
else
call s:DoStageUnpushed(info)
endif
return ''
elseif empty(info.paths)
continue
endif
@@ -7331,7 +7339,7 @@ function! s:BlameMaps(is_ftplugin) abort
call s:Map('n', '-', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 's', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 'u', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 'P', ':<C-U>exe <SID>BlameJump("^".v:count1)<CR>', '<silent>', ft)
call s:Map('n', 'P', ':<C-U>if !v:count<Bar>echoerr "Use ~ (or provide a count)"<Bar>else<Bar>exe <SID>BlameJump("^".v:count1)<Bar>endif<CR>', '<silent>', ft)
call s:Map('n', '~', ':<C-U>exe <SID>BlameJump("~".v:count1)<CR>', '<silent>', ft)
call s:Map('n', 'i', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>', ft)
call s:Map('n', 'o', ':<C-U>exe <SID>BlameCommit("split")<CR>', '<silent>', ft)
@@ -7999,7 +8007,7 @@ function! fugitive#MapJumps(...) abort
call s:Map('n', 'S', ':<C-U>echoerr "Use gO"<CR>', '<silent><unique>')
call s:Map('n', 'dq', ":<C-U>call fugitive#DiffClose()<CR>", '<silent>')
call s:Map('n', '-', ":<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>NavigateUp(v:count1))<Bar> if getline(1) =~# '^tree \x\{40,\}$' && empty(getline(2))<Bar>call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')<Bar>endif<CR>", '<silent>')
call s:Map('n', 'P', ":<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'^'.v:count1.<SID>Relative(':'))<CR>", '<silent>')
call s:Map('n', 'P', ":<C-U>if !v:count<Bar>echoerr 'Use ~ (or provide a count)'<Bar>else<Bar>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'^'.v:count1.<SID>Relative(':'))<Bar>endif<CR>", '<silent>')
call s:Map('n', '~', ":<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'~'.v:count1.<SID>Relative(':'))<CR>", '<silent>')
call s:Map('n', 'C', ":<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>", '<silent>')
call s:Map('n', 'cp', ":<C-U>echoerr 'Use gC'<CR>", '<silent><unique>')

View File

@@ -380,6 +380,9 @@ p Open the file or |fugitive-object| under the cursor in
*fugitive_P*
P Open the current file in the [count]th parent.
Experimental: In the "Unpushed" section of the status
buffer, this will populate the command line with a
":Git push" command for the commit under the cursor.
*fugitive_C*
C Open the commit containing the current file.