Support double quotes for all subcommand wrappers

This commit is contained in:
Tim Pope 2019-07-11 15:33:52 -04:00
parent e169595314
commit d0049b4417

View File

@ -2018,9 +2018,6 @@ augroup END
" Section: :Git " 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 function! s:GitExec(line1, line2, range, count, bang, mods, reg, args, dir) abort
if empty(a:args) if empty(a:args)
return s:StatusCommand(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, '', []) return s:StatusCommand(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, '', [])
@ -2058,8 +2055,8 @@ endfunction
function! s:Command(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort function! s:Command(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
let dir = a:0 ? s:Dir(a:1) : s:Dir() let dir = a:0 ? s:Dir(a:1) : s:Dir()
let args = s:SplitExpand(a:arg, s:Tree(dir)) 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) return s:GitExec(a:line1, a:line2, a:range, a:count, a:bang, a:mods, a:reg, args, dir) . after
endfunction endfunction
let s:exec_paths = {} let s:exec_paths = {}
@ -2103,6 +2100,9 @@ function! fugitive#Complete(...) abort
return call('fugitive#CompleteGit', a:000) return call('fugitive#CompleteGit', a:000)
endfunction endfunction
call s:command("-bang -nargs=? -range=-1 -complete=customlist,fugitive#CompleteGit Git", "Git")
call s:command("-bang -nargs=? -range=-1 -complete=customlist,fugitive#CompleteGit G", "")
" Section: :Gcd, :Glcd " Section: :Gcd, :Glcd
function! s:DirComplete(A, L, P) abort function! s:DirComplete(A, L, P) abort
@ -3168,9 +3168,9 @@ function! s:RebaseEdit(cmd, dir) abort
return a:cmd . ' +setlocal\ bufhidden=wipe\|' . escape('let b:fugitive_rebase_shas = ' . string(shas), ' ') . ' ' . rebase_todo return a:cmd . ' +setlocal\ bufhidden=wipe\|' . escape('let b:fugitive_rebase_shas = ' . string(shas), ' ') . ' ' . rebase_todo
endfunction endfunction
function! s:Merge(cmd, bang, mods, args, ...) abort function! s:MergeRebase(cmd, bang, mods, args, ...) abort
let dir = a:0 ? a:1 : s:Dir() let dir = a:0 ? a:1 : s:Dir()
let args = s:SplitExpand(a:args, s:Tree(dir)) let args = a:args
let mods = s:Mods(a:mods) let mods = s:Mods(a:mods)
if a:cmd =~# '^rebase' && s:HasOpt(args, '-i', '--interactive') if a:cmd =~# '^rebase' && s:HasOpt(args, '-i', '--interactive')
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . s:shellesc(args) let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . s:shellesc(args)
@ -3184,7 +3184,7 @@ function! s:Merge(cmd, bang, mods, args, ...) abort
endfor endfor
call writefile([], fugitive#Find('.git/rebase-merge/done', dir)) call writefile([], fugitive#Find('.git/rebase-merge/done', dir))
if a:bang if a:bang
return '' return 'exe'
endif endif
return s:RebaseEdit(mods . 'split', dir) return s:RebaseEdit(mods . 'split', dir)
elseif a:cmd =~# '^rebase' && s:HasOpt(args, '--edit-todo') && filereadable(fugitive#Find('.git/rebase-merge/git-rebase-todo', dir)) elseif a:cmd =~# '^rebase' && s:HasOpt(args, '--edit-todo') && filereadable(fugitive#Find('.git/rebase-merge/git-rebase-todo', dir))
@ -3300,7 +3300,7 @@ function! s:Merge(cmd, bang, mods, args, ...) abort
return 'cfirst' return 'cfirst'
endif endif
endif endif
return exists('err') ? 'echoerr '.string(err) : '' return exists('err') ? 'echoerr '.string(err) : 'exe'
endfunction endfunction
function! s:RebaseClean(file) abort function! s:RebaseClean(file) abort
@ -3324,6 +3324,21 @@ function! s:RebaseClean(file) abort
return '' return ''
endfunction endfunction
function! s:MergeCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
let [args, after] = s:SplitExpandChain(a:arg, s:Tree())
return s:MergeRebase('merge', a:bang, a:mods, args) . after
endfunction
function! s:RebaseCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
let [args, after] = s:SplitExpandChain(a:arg, s:Tree())
return s:MergeRebase('rebase', a:bang, a:mods, args) . after
endfunction
function! s:PullCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
let [args, after] = s:SplitExpandChain(a:arg, s:Tree())
return s:MergeRebase('pull --progress', a:bang, a:mods, args) . after
endfunction
augroup fugitive_merge augroup fugitive_merge
autocmd! autocmd!
autocmd VimLeavePre,BufDelete git-rebase-todo autocmd VimLeavePre,BufDelete git-rebase-todo
@ -3335,16 +3350,13 @@ augroup fugitive_merge
\ endif \ endif
autocmd BufEnter * nested autocmd BufEnter * nested
\ if exists('s:rebase_continue') | \ if exists('s:rebase_continue') |
\ exe s:Merge('rebase', 0, '', getfsize(fugitive#Find('.git/rebase-merge/git-rebase-todo', s:rebase_continue)) > 0 ? '--continue' : '--abort', remove(s:, 'rebase_continue')) | \ exe s:MergeRebase('rebase', 0, '', [getfsize(fugitive#Find('.git/rebase-merge/git-rebase-todo', s:rebase_continue)) > 0 ? '--continue' : '--abort'], remove(s:, 'rebase_continue')) |
\ endif \ endif
augroup END augroup END
call s:command("-nargs=? -bar -bang -complete=customlist,s:MergeComplete Gmerge " . call s:command("-nargs=? -bang -complete=customlist,s:MergeComplete Gmerge", "Merge")
\ "execute s:Merge('merge', <bang>0, '<mods>', <q-args>)") call s:command("-nargs=? -bang -complete=customlist,s:RebaseComplete Grebase", "Rebase")
call s:command("-nargs=? -bar -bang -complete=customlist,s:RebaseComplete Grebase " . call s:command("-nargs=? -bang -complete=customlist,s:PullComplete Gpull", "Pull")
\ "execute s:Merge('rebase', <bang>0, '<mods>', <q-args>)")
call s:command("-nargs=? -bar -bang -complete=customlist,s:PullComplete Gpull " .
\ "execute s:Merge('pull --progress', <bang>0, '<mods>', <q-args>)")
" Section: :Ggrep, :Glog " Section: :Ggrep, :Glog
@ -3418,7 +3430,7 @@ function! s:Grep(type, bang, arg) abort
if fugitive#GitVersion(2, 19) if fugitive#GitVersion(2, 19)
call add(cmd, '--column') call add(cmd, '--column')
endif endif
let args = s:SplitExpand(a:arg, s:Tree(dir)) let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir))
if exists(':chistory') if exists(':chistory')
call s:SetLocList(listnr, [], ' ', {'title': (listnr < 0 ? ':Ggrep ' : ':Glgrep ') . s:fnameescape(args)}) call s:SetLocList(listnr, [], ' ', {'title': (listnr < 0 ? ':Ggrep ' : ':Glgrep ') . s:fnameescape(args)})
else else
@ -3432,16 +3444,16 @@ function! s:Grep(type, bang, arg) abort
let list = map(readfile(tempfile), 's:GrepParseLine(cached, name_only, dir, v:val)') let list = map(readfile(tempfile), 's:GrepParseLine(cached, name_only, dir, v:val)')
call s:SetLocList(listnr, list, 'a') call s:SetLocList(listnr, list, 'a')
if !a:bang && !empty(list) if !a:bang && !empty(list)
return (listnr < 0 ? 'c' : 'l').'first' return (listnr < 0 ? 'c' : 'l').'first' . after
else else
return '' return after[1:-1]
endif endif
endfunction endfunction
function! s:Log(type, bang, line1, count, args) abort function! s:Log(type, bang, line1, count, args) abort
let dir = s:Dir() let dir = s:Dir()
let listnr = a:type =~# '^l' ? 0 : -1 let listnr = a:type =~# '^l' ? 0 : -1
let args = s:SplitExpand(a:args, s:Tree(dir)) let [args, after] = s:SplitExpandChain(a:args, s:Tree(dir))
let split = index(args, '--') let split = index(args, '--')
if split > 0 if split > 0
let paths = args[split : -1] let paths = args[split : -1]
@ -3496,17 +3508,17 @@ function! s:Log(type, bang, line1, count, args) abort
wincmd p wincmd p
endif endif
if !a:bang && len(s:GetLocList(listnr)) if !a:bang && len(s:GetLocList(listnr))
return a:type . 'first' return a:type . 'first' . after
endif endif
return '' return after[1:-1]
endfunction endfunction
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('c',<bang>0,<q-args>)") call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('c',<bang>0,<q-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Gcgrep :execute s:Grep('c',<bang>0,<q-args>)") call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Gcgrep :execute s:Grep('c',<bang>0,<q-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('l',<bang>0,<q-args>)") call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('l',<bang>0,<q-args>)")
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Glog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)") call s:command("-bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Glog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)")
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gclog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)") call s:command("-bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gclog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)")
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gllog :exe s:Log('l',<bang>0,<line1>,<count>,<q-args>)") call s:command("-bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gllog :exe s:Log('l',<bang>0,<line1>,<count>,<q-args>)")
" Section: :Gedit, :Gpedit, :Gsplit, :Gvsplit, :Gtabedit, :Gread " Section: :Gedit, :Gpedit, :Gsplit, :Gvsplit, :Gtabedit, :Gread