From 07661dc1020b8bc91faf1c530be36232295140f8 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 9 Jul 2019 04:28:19 -0400 Subject: [PATCH] Provide additional commit maps --- autoload/fugitive.vim | 33 +++++++++++++++++++++++---------- doc/fugitive.txt | 6 ++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 481c4f2..71cc696 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -4790,12 +4790,17 @@ function! s:ContainingCommit() abort return empty(commit) ? 'HEAD' : commit endfunction -function! s:SquashArgument() abort +function! s:SquashArgument(...) abort if &filetype == 'fugitive' - return matchstr(getline('.'), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze ') + let commit = matchstr(getline('.'), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze ') else - return s:Owner(@%) + let commit = s:Owner(@%) endif + return len(commit) && a:0 ? printf(a:1, commit) : commit +endfunction + +function! s:RebaseArgument() abort + return s:SquashArgument(' %s^') endfunction function! s:NavigateUp(count) abort @@ -4851,6 +4856,9 @@ function! fugitive#MapJumps(...) abort nnoremap ~ :exe 'Gedit ' . fnameescape(ContainingCommit().'~'.v:count1.Relative(':')) nnoremap C :exe 'Gedit ' . fnameescape(ContainingCommit()) + nnoremap c- :Gcommit - + nnoremap c :Gcommit + nnoremap c :Gcommit nnoremap co :echoerr 'Use CTRL-W C' nnoremap C :exe 'Gsplit ' . fnameescape(ContainingCommit()) nnoremap cp :echoerr 'Use gC' @@ -4863,17 +4871,22 @@ function! fugitive#MapJumps(...) abort nnoremap cva :Gcommit -v --amend nnoremap cvc :Gcommit -v nnoremap cf :Gcommit --fixup==SquashArgument() + nnoremap cF :Grebase --autosquash=RebaseArgument()Gcommit --fixup==SquashArgument() nnoremap cs :Gcommit --squash==SquashArgument() + nnoremap cS :Grebase --autosquash=RebaseArgument()Gcommit --squash==SquashArgument() nnoremap cA :Gcommit --edit --squash==SquashArgument() - nnoremap ri :Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','') - nnoremap rf :Grebase --autosquash=substitute(SquashArgument(),'.\+',' &^','') + nnoremap r- :Grebase - + nnoremap r :Grebase + nnoremap r :Grebase + nnoremap ri :Grebase --interactive=RebaseArgument() + nnoremap rf :Grebase --autosquash=RebaseArgument() nnoremap ru :Grebase --interactive @{upstream} nnoremap rp :Grebase --interactive @{push} - nnoremap rw :exe 'Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','')'s/^pick/reword/e - nnoremap rm :exe 'Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','')'s/^pick/edit/e - nnoremap rd :exe 'Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','')'s/^pick/drop/e - nnoremap rk :exe 'Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','')'s/^pick/drop/e - nnoremap rx :exe 'Grebase --interactive=substitute(SquashArgument(),'.\+',' &^','')'s/^pick/drop/e + nnoremap rw :Grebase --interactive=RebaseArgument()s/^pick/reword/e + nnoremap rm :Grebase --interactive=RebaseArgument()s/^pick/edit/e + nnoremap rd :Grebase --interactive=RebaseArgument()s/^pick/drop/e + nnoremap rk :Grebase --interactive=RebaseArgument()s/^pick/drop/e + nnoremap rx :Grebase --interactive=RebaseArgument()s/^pick/drop/e nnoremap rr :Grebase --continue nnoremap rs :Grebase --skip nnoremap re :Grebase --edit-todo diff --git a/doc/fugitive.txt b/doc/fugitive.txt index c39f24e..6669c6d 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -366,9 +366,15 @@ cva Amend the last commit with -v cf Create a `fixup!` commit for the commit under the cursor. +cF Create a `fixup!` commit for the commit under the + cursor and immediately rebase it. + cs Create a `squash!` commit for the commit under the cursor. +cS Create a `squash!` commit for the commit under the + cursor and immediately rebase it. + cA Create a `squash!` commit for the commit under the cursor and edit the message.