Unify :G and :Git

The principle difference between these two is that :G uses -bar while
:Git fakes it.  Faking it enables double quotes, but I don't really
trust it.
This commit is contained in:
Tim Pope 2019-07-06 10:37:57 -04:00
parent d0212919f3
commit 985861c083
2 changed files with 38 additions and 26 deletions

View File

@ -1430,10 +1430,6 @@ function! fugitive#CompleteObject(base, ...) abort
return map(entries, 's:fnameescape(v:val)')
endfunction
function! fugitive#Complete(...) abort
return call('fugitive#CompleteObject', a:000)
endfunction
" Section: Buffer auto-commands
function! s:ReplaceCmd(cmd) abort
@ -1961,23 +1957,36 @@ augroup END
" Section: :Git
call s:command("-bang -nargs=? -range=-1 -complete=customlist,fugitive#CompleteGit Git", "Git")
call s:command("-bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteGit G", "")
function! s:GitExec(line1, line2, range, count, bang, mods, reg, args, dir) abort
if empty(a:args)
return s:StatusCommand(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, '', [])
endif
if a:bang
return s:OpenExec((a:count > 0 ? a:count : '') . (a:count ? 'split' : 'edit'), a:mods, a:args, a:dir)
endif
let git = s:UserCommandList(a:dir)
if has('gui_running') && !has('win32')
call add(git, '--no-pager')
endif
let pre = ''
if has('nvim') && executable('env')
let pre .= 'env GIT_TERMINAL_PROMPT=0 '
endif
return 'exe ' . string('!' . escape(pre . s:shellesc(git + a:args), '!#%'))
endfunction
function! s:GitCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
let dir = s:Dir()
let tree = s:Tree(dir)
let [args, after] = s:SplitExpandChain(a:arg, tree)
if a:bang
return s:OpenExec((a:count > 0 ? a:count : '') . (a:count ? 'split' : 'edit'), a:mods, args, dir) . after
endif
let git = s:UserCommand(dir)
if has('gui_running') && !has('win32')
let git .= ' --no-pager'
endif
if has('nvim') && executable('env')
let git = 'env GIT_TERMINAL_PROMPT=0 ' . git
endif
let cmd = "exe '!'.escape(" . string(git . ' ' . s:shellesc(args)) . ",'!#%')"
return cmd . after
let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir))
return s:GitExec(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, args, dir) . after
endfunction
function! s:Command(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
let dir = a:0 ? s:Dir(a:1) : s:Dir()
let args = s:SplitExpand(a:arg, s:Tree(dir))
return s:GitExec(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, args, dir)
endfunction
let s:exec_paths = {}
@ -2017,6 +2026,10 @@ function! fugitive#CompleteGit(lead, ...) abort
return filter(results, 'strpart(v:val, 0, strlen(a:lead)) ==# a:lead')
endfunction
function! fugitive#Complete(...) abort
return call('fugitive#CompleteGit', a:000)
endfunction
" Section: :Gcd, :Glcd
function! s:DirComplete(A, L, P) abort
@ -2038,7 +2051,6 @@ call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Glcd :exe
" Section: :Gstatus
call s:command("-bar -bang -range=-1 Gstatus", "Status")
call s:command("-bar -bang -range=-1 G", "Status")
function! s:StatusCommand(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
let dir = a:0 ? a:1 : s:Dir()

View File

@ -15,12 +15,16 @@ COMMANDS *fugitive-commands*
These commands are local to the buffers in which they work (generally, buffers
that are part of Git repositories).
*fugitive-:G* *fugitive-:Gstatus*
:G Bring up a summary window vaguely akin to git-status.
:Gstatus Press g? or see |fugitive-mappings| for usage.
*fugitive-:Git*
:Git [args] Run an arbitrary git command. Similar to :!git [args]
but chdir to the repository tree first.
:Git {args} Run an arbitrary git command. Similar to :!git [args]
:G {args} but chdir to the repository tree first.
*fugitive-:Git!*
:Git! [args] Like |:Git|, but capture the output into a temp file,
:Git! {args} Like |:Git|, but capture the output into a temp file,
and |:split| that that temp file. Use :0Git to
|:edit| the temp file instead.
@ -30,10 +34,6 @@ that are part of Git repositories).
*fugitive-:Glcd*
:Glcd [directory] |:lcd| relative to the repository.
*fugitive-:Gstatus* *fugitive-:G*
:G Bring up a summary window vaguely akin to git-status.
:Gstatus Press g? or see |fugitive-mappings| for usage.
*fugitive-:Gcommit*
:Gcommit [args] A wrapper around git-commit. Unless the arguments
given would skip the invocation of an editor (e.g.,