Replace :Gcommit/:Grevert with standard job runner

This commit is contained in:
Tim Pope
2020-01-18 02:09:00 -05:00
parent c989c1f59e
commit 22255613f7
2 changed files with 44 additions and 144 deletions

View File

@@ -3603,109 +3603,28 @@ function! s:CommitInteractive(line1, line2, range, bang, mods, args, patch) abor
endif endif
endfunction endfunction
function! s:CommitSubcommand(line1, line2, range, bang, mods, args, ...) abort function! s:CommitSubcommand(line1, line2, range, bang, mods, args) abort
let mods = substitute(s:Mods(a:mods), '\C\<tab\>', '-tab', 'g') let argv = copy(a:args)
let dir = a:0 ? a:1 : s:Dir() let i = 0
let tree = s:Tree(dir) while get(argv, i, '--') !=# '--'
let msgfile = fugitive#Find('.git/COMMIT_EDITMSG', dir) if argv[i] =~# '^-[apzsneiovq].'
let outfile = tempname() call insert(argv, argv[i][0:1])
try let argv[i+1] = '-' . argv[i+1][2:-1]
if s:winshell() || &shellcmdflag ==# '-Command'
let command = 'set GIT_EDITOR=false& '
else else
let command = 'env GIT_EDITOR=false ' let i += 1
endif endif
let argv = a:args endwhile
let i = 0 if s:HasOpt(argv, '-i', '--interactive')
while get(argv, i, '--') !=# '--' return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 0)
if argv[i] =~# '^-[apzsneiovq].' elseif s:HasOpt(argv, '-p', '--patch')
call insert(argv, argv[i][0:1]) return s:CommitInteractive(a:line1, a:line2, a:range, a:bang, a:mods, argv, 1)
let argv[i+1] = '-' . argv[i+1][2:-1] else
else return {}
let i += 1 endif
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 =~# '\<tab\>'
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
endfunction endfunction
function! s:RevertSubcommand(line1, line2, range, bang, mods, args) abort function! s:RevertSubcommand(line1, line2, range, bang, mods, args) abort
let dir = s:Dir() return {'args': ['revert', '--edit'] + a:args}
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)
endfunction endfunction
function! fugitive#CommitComplete(A, L, P) abort 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')) return s:CompleteSub('revert', a:A, a:L, a:P, function('s:CompleteRevision'))
endfunction endfunction
function! s:FinishCommit() abort
let buf = +expand('<abuf>')
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 " Section: :Gmerge, :Grebase, :Gpull
function! fugitive#MergeComplete(A, L, P) abort function! fugitive#MergeComplete(A, L, P) abort
@@ -4619,11 +4528,6 @@ function! fugitive#WqCommand(...) abort
endif endif
endfunction 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 " Section: :Gpush, :Gfetch
function! fugitive#PushComplete(A, L, P) abort function! fugitive#PushComplete(A, L, P) abort
@@ -5863,14 +5767,14 @@ function! fugitive#MapJumps(...) abort
nnoremap <buffer> c<Space> :Git commit<Space> nnoremap <buffer> c<Space> :Git commit<Space>
nnoremap <buffer> c<CR> :Git commit<CR> nnoremap <buffer> c<CR> :Git commit<CR>
nnoremap <buffer> cv<Space> :Git commit -v<Space> nnoremap <buffer> cv<Space> :tab Git commit -v<Space>
nnoremap <buffer> cv<CR> :Git commit -v<CR> nnoremap <buffer> cv<CR> :tab Git commit -v<CR>
nnoremap <buffer> <silent> ca :<C-U>Gcommit --amend<CR> nnoremap <buffer> <silent> ca :<C-U>Gcommit --amend<CR>
nnoremap <buffer> <silent> cc :<C-U>Gcommit<CR> nnoremap <buffer> <silent> cc :<C-U>Gcommit<CR>
nnoremap <buffer> <silent> ce :<C-U>Gcommit --amend --no-edit<CR> nnoremap <buffer> <silent> ce :<C-U>Gcommit --amend --no-edit<CR>
nnoremap <buffer> <silent> cw :<C-U>Gcommit --amend --only<CR> nnoremap <buffer> <silent> cw :<C-U>Gcommit --amend --only<CR>
nnoremap <buffer> <silent> cva :<C-U>Gcommit -v --amend<CR> nnoremap <buffer> <silent> cva :<C-U>tab Gcommit -v --amend<CR>
nnoremap <buffer> <silent> cvc :<C-U>Gcommit -v<CR> nnoremap <buffer> <silent> cvc :<C-U>tab Gcommit -v<CR>
nnoremap <buffer> <silent> cRa :<C-U>Gcommit --reset-author --amend<CR> nnoremap <buffer> <silent> cRa :<C-U>Gcommit --reset-author --amend<CR>
nnoremap <buffer> <silent> cRe :<C-U>Gcommit --reset-author --amend --no-edit<CR> nnoremap <buffer> <silent> cRe :<C-U>Gcommit --reset-author --amend --no-edit<CR>
nnoremap <buffer> <silent> cRw :<C-U>Gcommit --reset-author --amend --only<CR> nnoremap <buffer> <silent> cRw :<C-U>Gcommit --reset-author --amend --only<CR>

View File

@@ -17,11 +17,13 @@ that are part of Git repositories).
*:Git* *fugitive-:G* *:Git* *fugitive-:G*
:Git {args} Run an arbitrary git command and display any output. :Git {args} Run an arbitrary git command and display any output.
:G {args} Any file the command edits (for example, a commit :G {args} On UNIX this uses a pty and on other platforms it uses
message) will be loaded into a split window. Closing a pipe, which will cause some behavior differences
that window will resume running the command. A few such as the absence of progress bars. Any file the
commands have different behavior; these are documented command edits (for example, a commit message) will be
below. 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! {args} Run an arbitrary git command, capture output to a temp
:Git --paginate {args} file, and |:split| that temp file. Use :0Git to :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. :G Press g? or see |fugitive-maps| for usage.
:Gstatus :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* *:Gblame*
:Git blame [flags] Run git-blame [flags] on the current file and open the :Git blame [flags] Run git-blame [flags] on the current file and open the
:Gblame [flags] results in a scroll-bound vertical split. 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*
:Git mergetool [args] Like |:Git-difftool|, but target merge conflicts. :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* *:Git-merge* *:Gmerge*
:Gmerge [args] Deprecated alias for |:Git| merge. Use |:Git-mergetool| :Gmerge [args] Deprecated alias for |:Git| merge. Use |:Git-mergetool|
to get the old behavior of loading merge conflicts to get the old behavior of loading merge conflicts
@@ -114,6 +104,12 @@ that are part of Git repositories).
*:Git-rebase* *:Grebase* *:Git-rebase* *:Grebase*
:Grebase [args] Deprecated alias for |:Git| rebase. :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* *:Glog*
:Gclog[!] [args] Use git-log [args] to load the commit history into the :Gclog[!] [args] Use git-log [args] to load the commit history into the
:Glog[!] [args] |quickfix| list. Jumps to the first commit unless [!] :Glog[!] [args] |quickfix| list. Jumps to the first commit unless [!]