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)') return map(entries, 's:fnameescape(v:val)')
endfunction endfunction
function! fugitive#Complete(...) abort
return call('fugitive#CompleteObject', a:000)
endfunction
" Section: Buffer auto-commands " Section: Buffer auto-commands
function! s:ReplaceCmd(cmd) abort function! s:ReplaceCmd(cmd) abort
@ -1961,23 +1957,36 @@ augroup END
" Section: :Git " Section: :Git
call s:command("-bang -nargs=? -range=-1 -complete=customlist,fugitive#CompleteGit Git", "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 function! s:GitCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
let dir = s:Dir() let dir = s:Dir()
let tree = s:Tree(dir) let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir))
let [args, after] = s:SplitExpandChain(a:arg, tree) return s:GitExec(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, args, dir) . after
if a:bang endfunction
return s:OpenExec((a:count > 0 ? a:count : '') . (a:count ? 'split' : 'edit'), a:mods, args, dir) . after
endif function! s:Command(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
let git = s:UserCommand(dir) let dir = a:0 ? s:Dir(a:1) : s:Dir()
if has('gui_running') && !has('win32') let args = s:SplitExpand(a:arg, s:Tree(dir))
let git .= ' --no-pager' return s:GitExec(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, args, dir)
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
endfunction endfunction
let s:exec_paths = {} 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') return filter(results, 'strpart(v:val, 0, strlen(a:lead)) ==# a:lead')
endfunction endfunction
function! fugitive#Complete(...) abort
return call('fugitive#CompleteGit', a:000)
endfunction
" Section: :Gcd, :Glcd " Section: :Gcd, :Glcd
function! s:DirComplete(A, L, P) abort 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 " Section: :Gstatus
call s:command("-bar -bang -range=-1 Gstatus", "Status") 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 function! s:StatusCommand(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
let dir = a:0 ? a:1 : s:Dir() 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 These commands are local to the buffers in which they work (generally, buffers
that are part of Git repositories). 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* *fugitive-:Git*
:Git [args] Run an arbitrary git command. Similar to :!git [args] :Git {args} Run an arbitrary git command. Similar to :!git [args]
but chdir to the repository tree first. :G {args} but chdir to the repository tree first.
*fugitive-:Git!* *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 and |:split| that that temp file. Use :0Git to
|:edit| the temp file instead. |:edit| the temp file instead.
@ -30,10 +34,6 @@ that are part of Git repositories).
*fugitive-:Glcd* *fugitive-:Glcd*
:Glcd [directory] |:lcd| relative to the repository. :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* *fugitive-:Gcommit*
:Gcommit [args] A wrapper around git-commit. Unless the arguments :Gcommit [args] A wrapper around git-commit. Unless the arguments
given would skip the invocation of an editor (e.g., given would skip the invocation of an editor (e.g.,