From 22255613f798fe0ab0ecbe347079874e39863e9e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 18 Jan 2020 02:09:00 -0500 Subject: [PATCH] Replace :Gcommit/:Grevert with standard job runner --- autoload/fugitive.vim | 138 +++++++----------------------------------- doc/fugitive.txt | 50 +++++++-------- 2 files changed, 44 insertions(+), 144 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 2c2d0aa..246cdc5 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3603,109 +3603,28 @@ function! s:CommitInteractive(line1, line2, range, bang, mods, args, patch) abor endif endfunction -function! s:CommitSubcommand(line1, line2, range, bang, mods, args, ...) abort - let mods = substitute(s:Mods(a:mods), '\C\', '-tab', 'g') - let dir = a:0 ? a:1 : s:Dir() - let tree = s:Tree(dir) - let msgfile = fugitive#Find('.git/COMMIT_EDITMSG', dir) - let outfile = tempname() - try - if s:winshell() || &shellcmdflag ==# '-Command' - let command = 'set GIT_EDITOR=false& ' +function! s:CommitSubcommand(line1, line2, range, bang, mods, args) abort + let argv = copy(a:args) + let i = 0 + while get(argv, i, '--') !=# '--' + if argv[i] =~# '^-[apzsneiovq].' + call insert(argv, argv[i][0:1]) + let argv[i+1] = '-' . argv[i+1][2:-1] else - let command = 'env GIT_EDITOR=false ' + let i += 1 endif - let argv = a:args - let i = 0 - while get(argv, i, '--') !=# '--' - if argv[i] =~# '^-[apzsneiovq].' - call insert(argv, argv[i][0:1]) - let argv[i+1] = '-' . argv[i+1][2:-1] - else - let i += 1 - endif - endwhile - let command .= s:UserCommand(dir, ['commit'] + argv) - if (&autowrite || &autowriteall) && !a:0 - silent! wall - endif - if s:HasOpt(argv, '-i', '--interactive') - return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 0) - elseif s:HasOpt(argv, '-p', '--patch') - return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 1) - else - let [error_string, exec_error] = s:TempCmd(outfile, command) - let errors = split(error_string, "\n") - endif - if !has('gui_running') - redraw! - endif - if !exec_error - echo join(errors, "\n") - if filereadable(outfile) - echo join(readfile(outfile), "\n") - endif - call fugitive#ReloadStatus(dir, 1) - return '' - else - let error = get(errors,-2,get(errors,-1,'!')) - if error =~# 'false''\=\.$' - let i = 0 - while get(argv, i, '--') !=# '--' - if argv[i] =~# '^\%(-[eips]\|-[CcFm].\+\|--edit\|--interactive\|--patch\|--signoff\|--reedit-message=.*\|--reuse-message=.*\|--file=.*\|--message=.*\)$' - call remove(argv, i) - elseif argv[i] =~# '^\%(-[CcFm]\|--reedit-message\|--reuse-message\|--file\|--message\)$' - call remove(argv, i, i + 1) - else - if argv[i] =~# '^--cleanup\>' - let cleanup = 1 - endif - let i += 1 - endif - endwhile - call insert(argv, '--no-signoff', i) - call insert(argv, '--no-interactive', i) - call insert(argv, '--no-edit', i) - if !exists('cleanup') - call insert(argv, '--cleanup=strip') - endif - call extend(argv, ['-F', msgfile], 'keep') - if (bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&modified) || a:line2 == 0 - execute mods . 'keepalt edit' s:fnameescape(msgfile) - elseif s:HasOpt(argv, '-v') || mods =~# '\' - execute mods . 'keepalt -tabedit' s:fnameescape(msgfile) - else - execute mods . 'keepalt split' s:fnameescape(msgfile) - endif - let b:fugitive_commit_arguments = argv - setlocal bufhidden=wipe filetype=gitcommit - return '1' - elseif empty(errors) - let out = readfile(outfile) - echo get(out, -1, '') =~# 'stash\|\d' ? get(out, -2, '') : get(out, -1, '') - return '' - else - echo join(errors, "\n") - return '' - endif - endif - catch /^fugitive:/ - return 'echoerr ' . string(v:exception) - finally - call delete(outfile) - endtry + endwhile + if s:HasOpt(argv, '-i', '--interactive') + return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 0) + elseif s:HasOpt(argv, '-p', '--patch') + return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 1) + else + return {} + endif endfunction function! s:RevertSubcommand(line1, line2, range, bang, mods, args) abort - let dir = s:Dir() - let no_commit = s:HasOpt(a:args, '-n', '--no-commit', '--no-edit', '--abort', '--continue', '--quit') - let cmd = s:UserCommand(dir, ['revert'] + (no_commit ? [] : ['-n']) + a:args) - let [out, exec_error] = s:SystemError(cmd) - call fugitive#ReloadStatus(dir, 1) - if no_commit || exec_error - return 'echo ' . string(substitute(out, "\n$", '', '')) - endif - return s:CommitSubcommand(a:line1, a:line2, a:range, a:bang, a:mods, [], dir) + return {'args': ['revert', '--edit'] + a:args} endfunction function! fugitive#CommitComplete(A, L, P) abort @@ -3729,16 +3648,6 @@ function! fugitive#RevertComplete(A, L, P) abort return s:CompleteSub('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') - if !empty(args) - call setbufvar(buf, 'fugitive_commit_arguments', []) - return s:CommitSubcommand(-1, -1, 0, 0, '', args, s:Dir(buf)) - endif - return '' -endfunction - " Section: :Gmerge, :Grebase, :Gpull function! fugitive#MergeComplete(A, L, P) abort @@ -4619,11 +4528,6 @@ function! fugitive#WqCommand(...) abort endif endfunction -augroup fugitive_commit - autocmd! - autocmd VimLeavePre,BufDelete COMMIT_EDITMSG execute substitute(s:FinishCommit(), '\C^echoerr \(''[^'']*''\)*', 'redraw|echohl ErrorMsg|echo \1|echohl NONE', '') -augroup END - " Section: :Gpush, :Gfetch function! fugitive#PushComplete(A, L, P) abort @@ -5863,14 +5767,14 @@ function! fugitive#MapJumps(...) abort nnoremap c :Git commit nnoremap c :Git commit - nnoremap cv :Git commit -v - nnoremap cv :Git commit -v + nnoremap cv :tab Git commit -v + nnoremap cv :tab Git commit -v nnoremap ca :Gcommit --amend nnoremap cc :Gcommit nnoremap ce :Gcommit --amend --no-edit nnoremap cw :Gcommit --amend --only - nnoremap cva :Gcommit -v --amend - nnoremap cvc :Gcommit -v + nnoremap cva :tab Gcommit -v --amend + nnoremap cvc :tab Gcommit -v nnoremap cRa :Gcommit --reset-author --amend nnoremap cRe :Gcommit --reset-author --amend --no-edit nnoremap cRw :Gcommit --reset-author --amend --only diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 31335bb..efb4425 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -17,11 +17,13 @@ that are part of Git repositories). *:Git* *fugitive-:G* :Git {args} Run an arbitrary git command and display any output. -:G {args} Any file the command edits (for example, a commit - message) will be loaded into a split window. Closing - that window will resume running the command. A few - commands have different behavior; these are documented - below. +:G {args} On UNIX this uses a pty and on other platforms it uses + a pipe, which will cause some behavior differences + such as the absence of progress bars. Any file the + command edits (for example, a commit message) will be + loaded into a split window. Closing that window will + resume running the command. A few Git subcommands + have different behavior; these are documented below. :Git! {args} Run an arbitrary git command, capture output to a temp :Git --paginate {args} file, and |:split| that temp file. Use :0Git to @@ -33,28 +35,6 @@ that are part of Git repositories). :G Press g? or see |fugitive-maps| for usage. :Gstatus - *:Git-commit* *:Gcommit* -:Git commit [args] A wrapper around git-commit. Unless the arguments -:Gcommit [args] given would skip the invocation of an editor (e.g., - -m), a split window will be used to obtain a commit - message, or a new tab if -v is given. Write and close - the window (:wq) to finish the commit. To cancel, use - an empty message. - - *:Git-revert* *:Grevert* -:Git revert [args] A wrapper around git-revert. Similar to |:Gcommit|. -:Grevert [args] - - *:Git-push* *:Gpush* -:Git push [args] Invoke git-push, load the results into the |quickfix| -:Gpush [args] list, and invoke |:cwindow| to reveal any errors. - |:Dispatch| is used if available for asynchronous - invocation. - - *:Git-fetch* *:Gfetch* -:Git fetch [args] Like |:Gpush|, but for git-fetch. -:Gfetch [args] - *:Git-blame* *:Gblame* :Git blame [flags] Run git-blame [flags] on the current file and open the :Gblame [flags] results in a scroll-bound vertical split. The @@ -103,6 +83,16 @@ that are part of Git repositories). *:Git-mergetool* :Git mergetool [args] Like |:Git-difftool|, but target merge conflicts. + *:Git-push* *:Gpush* +:Git push [args] Invoke git-push, load the results into the |quickfix| +:Gpush [args] list, and invoke |:cwindow| to reveal any errors. + |:Dispatch| is used if available for asynchronous + invocation. + + *:Git-fetch* *:Gfetch* +:Git fetch [args] Like |:Gpush|, but for git-fetch. +:Gfetch [args] + *:Git-merge* *:Gmerge* :Gmerge [args] Deprecated alias for |:Git| merge. Use |:Git-mergetool| to get the old behavior of loading merge conflicts @@ -114,6 +104,12 @@ that are part of Git repositories). *:Git-rebase* *:Grebase* :Grebase [args] Deprecated alias for |:Git| rebase. + *:Git-commit* *:Gcommit* +:Gcommit [args] Deprecated alias for |:Git| commit. + + *:Git-revert* *:Grevert* +:Grevert [args] Deprecated alias for |:Git| revert. + *:Gclog* *:Glog* :Gclog[!] [args] Use git-log [args] to load the commit history into the :Glog[!] [args] |quickfix| list. Jumps to the first commit unless [!]