From 665cec73d90d6dc62351087a0bcc8c4a62d937f1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 25 Jul 2019 22:27:24 -0400 Subject: [PATCH] Provide :Grevert --- autoload/fugitive.vim | 22 +++++++++++++++++++++- doc/fugitive.txt | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index c3459c8..5fe5e20 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3031,7 +3031,7 @@ function! s:StagePatch(lnum1,lnum2) abort return s:ReloadStatus() endfunction -" Section: :Gcommit +" Section: :Gcommit, :Grevert function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort let mods = substitute(s:Mods(a:mods), '\C\', '-tab', 'g') @@ -3140,6 +3140,19 @@ function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args endtry endfunction +function! s:RevertCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort + let dir = s:Dir() + let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir)) + let no_commit = s:HasOpt(args, '-n', '--no-commit', '--no-edit') + let cmd = s:UserCommand(dir) . ' revert ' . (no_commit ? '' : '-n ') . s:shellesc(args) + let [out, exec_error] = s:SystemError(cmd) + call fugitive#ReloadStatus(-1, 1) + if no_commit || exec_error + return 'echo ' . string(substitute(out, "\n$", '', '')) . after + endif + return s:CommitCommand(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, after, [], dir) +endfunction + function! s:CommitComplete(A, L, P) abort if a:A =~# '^--fixup=\|^--squash=' let commits = s:LinesError(['log', '--pretty=format:%s', '@{upstream}..'])[0] @@ -3157,6 +3170,10 @@ function! s:CommitComplete(A, L, P) abort return [] endfunction +function! s:RevertComplete(A, L, P) abort + return s:CompleteSubcommand('revert', a:A, a:L, a:P, function('s:CompleteRevision')) +endfunction + function! s:FinishCommit() abort let buf = +expand('') let args = getbufvar(buf, 'fugitive_commit_arguments') @@ -3172,6 +3189,7 @@ function! s:FinishCommit() abort endfunction call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit", "Commit") +call s:command("-nargs=? -complete=customlist,s:RevertComplete Grevert", "Revert") " Section: :Gmerge, :Grebase, :Gpull @@ -4934,6 +4952,8 @@ function! fugitive#MapJumps(...) abort nnoremap cs :Gcommit --squash==SquashArgument() nnoremap cS :Grebase --autosquash=RebaseArgument()Gcommit --squash==SquashArgument() nnoremap cA :Gcommit --edit --squash==SquashArgument() + nnoremap cr :Grevert =SquashArgument() + nnoremap cR :Grevert =SquashArgument() nnoremap c? :help fugitive_c nnoremap cz :G stash diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 15c56cf..020a98a 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -42,6 +42,9 @@ that are part of Git repositories). the window (:wq) to finish the commit. To cancel, use an empty message. + *fugitive-:Grevert* +:Grevert [args] A wrapper around git-revert. Similar to |:Gcommit|. + *fugitive-:Gmerge* :Gmerge [args] Calls git-merge and loads errors and conflicted files into the |quickfix| list. Opens a |:Gcommit| style @@ -395,6 +398,8 @@ cS Create a `squash!` commit for the commit under the cA Create a `squash!` commit for the commit under the cursor and edit the message. +cr Revert the commit under the cursor. + c Populate command line with ":Gcommit ". c? Show this help.